I'm building a program that use the Dart's AST library, and it works fine as long as I use the Dart interpreter to run the program (dart filename.dart).
Once I want to compile the program (dart compile filename.dart), the program can't load the file and I have this stacktrace:
#0 _PhysicalFile.readAsStringSync (package:analyzer/file_system/physical_file_system.dart:184)
#1 FolderBasedDartSdk.languageVersion (package:analyzer/src/dart/sdk/sdk.dart:400)
#2 FeatureSetProvider.build (package:analyzer/src/dart/analysis/feature_set_provider.dart:143)
#3 AnalysisDriver._createFileTracker (package:analyzer/src/dart/analysis/driver.dart:1500)
#4 new AnalysisDriver (package:analyzer/src/dart/analysis/driver.dart:291)
#5 ContextBuilder.buildDriver (package:analyzer/src/context/builder.dart:119)
#6 ContextBuilderImpl.createContext (package:analyzer/src/dart/analysis/context_builder.dart:94)
#7 new AnalysisContextCollectionImpl (package:analyzer/src/dart/analysis/analysis_context_collection.dart:55)
#8 _createAnalysisContext (package:analyzer/dart/analysis/utilities.dart:125)
#9 resolveFile (package:analyzer/dart/analysis/utilities.dart:115)
#10 main (package:DartProjects/dartprojects.dart:122)
#11 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299)
#12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168)
I took a look at the source code to see where could be the error, and it seems that in package:analyzer/src/dart/sdk/sdk.dart it tries to get the langage version file, but instead of using the PATH to know where my dart sdk is, it tries to find it in my InteliJ folder, which fails. Also, I tried to run it on a freshly created VM, and it fails too.
Here is the code that produce this output:
import 'dart:io';
import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
void main(List<String> arguments) async {
final fileName = Directory.current.path + r'\test.dart';
var source = null;
try {
source = await resolveFile(path: fileName);
} catch (e, s) {
print('${s}');
return;
}
}
Thanks for your help.
Not a good workaround.
Copy the "version" file from the Dart SDK folder to the root of your project.
The analyzer will take it and use it.
This will work if your compiled file is in the "bin" folder.
This is not a good workaround.
P.S.
This is called a hack.
Related
I have been trying to generate dart diagrams for my code but the below error:
C:\Users\Foldername\AppData\Local\Pub\Cache\bin>dart pub global run dcdg
C:\Users\Foldername\AppData\Local\Pub\Cache\bin\lib
Unhandled exception:
Bad state: Unable to find the context to C:\Users\Foldername\AppData\Local\Pub\Cache\bin\lib\.env.dart
#0 AnalysisContextCollectionImpl.contextFor (package:analyzer/src/dart/analysis/analysis_context_collection.dart:106:5)
#1 findClassElements (package:dcdg/src/find_class_elements.dart:46:39)
#2 main (file:///C:/Users/Foldername/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/dcdg-4.0.1/bin/dcdg.dart:35:25)
#3 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
1- I have activated the package.
2- I have updated it to the latest.
3- Environment variables are correctly set.
I still don't understand why does it not allow me to create class diagrams for my code. Anyone has any answers?
I think that probably in your project are dependencies that use code-generation (with build_runner) like: freezed, auto_route, localizely or hive. Package dcdg at the moment (ver. 4.1.0) have issues for generating PlantUML file for such projects. If you want to use dcdg you need to refactor your code and remove such dependencies.
Here is github issue related to your case.
I'm working on school project, which requires to show some simple data from mysql database in browser. I've read, that SQLJocky doesn't work in browser so I decided to make it like server-client app and run db on server side (got inspiration here: https://dart-lang.github.io/server/codelab/). But it didn't work, failed in creating client api with message:
*in ShutdownIsolate: Unhandled exception:
IsolateSpawnException: Unable to spawn isolate: Unhandled exception:
Load Error for "package:sqljocky/sqljocky.dart": No mapping for 'sqljocky' package when resolving 'package:sqljocky/sqljocky.dart'.
#0 _asyncLoadErrorCallback (dart:_builtin:155)
#1 _asyncLoadError (dart:_builtin:566)
#2 _loadPackage (dart:_builtin:605)
#3 _loadData (dart:_builtin:637)
#4 _loadDataAsync (dart:_builtin:657)
#5 _loadScriptCallback (dart:_builtin:153)
#6 _handleLoaderReply (dart:_builtin:370)
#7 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)
'file:///home/alenka/dart-pokusy/server-side-app/one-hour-codelab/server/7-serve/lib/server/dbConnector.dart': error: line 1 pos 1: library handler failed
import 'package:sqljocky/sqljocky.dart';
^
#0 Isolate.spawnUri.<spawnUri_async_body> (dart:isolate-patch/isolate_patch.dart)
#1 _asyncErrorWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:34)
#2 _RootZone.runBinary (dart:async/zone.dart:1154)
#3 _Future._propagateToListeners.handleError (dart:async/future_impl.dart:579)
#4 _Future._propagateToListeners (dart:async/future_impl.dart:641)
#5 _Future._completeError (dart:async/future_impl.dart:432)
#6 _SyncCompleter._completeError (dart:async/future_impl.dart:56)
#7 _Completer.completeError (dart:async/future_impl.dart:27)
#8 Isolate._spawnCommon.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:439)
#9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)*
Does anyone have idea how to solve this problem, or how to get data from db in browser differently?
Code added containing things from SQLJocky:
`import 'package:sqljocky/sqljocky.dart';
import 'dart:async';
...
#ApiMethod(path: 'connect')
Future<List<String>> dbConnect() async {
List<String> rows = [];
print('called dbConnect');
var pool = new ConnectionPool(
host: 'localhost',
port: 3306,
user: "root",
password: null,
db: 'project',
max: 5);
print('connection created');
var results = await pool.query('select * from User');
print('gonna write something from db');
results.forEach( (row){
print('Name: ${row[0]}, password: ${row[1]}');
rows.add('Name: ${row[0]}, password: ${row[1]}');
});
return rows;
}
`
Isolate your server side code and client side code into separates projects with their own pubspec.yaml.
I've found that sqljocky doesn't play nice with some of the client side libraries when both are in the pubspec.yaml.
This question already has an answer here:
WebStorm DartUnit with test api, run/debug error
(1 answer)
Closed 7 years ago.
This should be trivial but it is not working as I think it should. I am new to WebStorm.
I have a simple test taken from Dart's new test offering at https://pub.dartlang.org/packages/test
.dart
import "package:test/test.dart";
void main() {
test("String.split() splits the string on the delimiter", () {
var string = "foo,bar,baz";
expect(string.split(","), equals(["foo", "bar", "baz"]));
});
test("String.trim() removes surrounding whitespace", () {
var string = " foo ";
expect(string.trim(), equals("foo"));
});
}
Running this simple test gives the following exception:
J:\dart\dart-sdk\bin\dart.exe --ignore-unrecognized-flags --checked --package-root=J:\workspace\epimss\dart\epimss_shared\packages --enable-vm-service:60110 --trace_service_pause_events C:\Users\st.clair.clarke\AppData\Local\Temp\jetbrains_unit_config.dart
Testing started at 3:07 AM ...
Observatory listening on http://127.0.0.1:60110
Unhandled exception:
No top-level setter 'unittestConfiguration=' declared.
NoSuchMethodError: method not found: 'unittestConfiguration='
Receiver: top-level
Arguments: [Instance of 'JetBrainsUnitConfig']
#0 NoSuchMethodError._throwNew (dart:core-patch/errors_patch.dart:188)
#1 main (file:///x:/Users/zang/AppData/Local/Temp/jetbrains_unit_config.dart:10:3)
#2 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:259)
#3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)
Process finished with exit code 255
The problem seems to be the line unittestConfiguration = config; in the jetbrains configuration - something is expected for the config.
Any help is appreciated.
According to this issue, test package is not yet supported by WebStorm's testing framework.
You have two ways right now:
Run it as usual dart application, not as a test
Use deprecated unittest package instead of test until issue is resolved.
I have a new dart project but I fail to add unit tests.
But I am new to DART so perhaps I am punished as all rookies should ... or should they!?
Error when running unit tests
Error: Exception: No constructor 'Future.value' declared in class 'Future'.
NoSuchMethodError : method not found: 'Future.value'
Receiver: Type: class 'Future'
Arguments: []
Stack Trace: #0 _defer (http://127.0.0.1:3030/Users/gunnar/git/chessbuddy/src/main/webapp/dart/chessmodel/test/packages/unittest/unittest.dart:671:20)
#1 _ensureInitialized (http://127.0.0.1:3030/Users/gunnar/git/chessbuddy/src/main/webapp/dart/chessmodel/test/packages/unittest/unittest.dart:830:11)
#2 ensureInitialized (http://127.0.0.1:3030/Users/gunnar/git/chessbuddy/src/main/webapp/dart/chessmodel/test/packages/unittest/unittest.dart:809:21)
#3 group (http://127.0.0.1:3030/Users/gunnar/git/chessbuddy/src/main/webapp/dart/chessmodel/test/packages/unittest/unittest.dart:585:20)
#4 main (http://127.0.0.1:3030/Users/gunnar/git/chessbuddy/src/main/webapp/dart/chessmodel/test/test_runner.dart:9:8)
FAIL
pub info
€ pub --version
Pub 0.4.7+1.r21548
€ pub cache list
{"packages":
{"browser":{"version":"0.4.7+1","location":"/Users/gunnar/.pub-cache/hosted/pub.dartlang.org/browser-0.4.7+1"},
"meta":{"version":"0.4.7+1","location":"/Users/gunnar/.pub-cache/hosted/pub.dartlang.org/meta-0.4.7+1"},
"stagexl":{"version":"0.7.4","location":"/Users/gunnar/.pub-cache/hosted/pub.dartlang.org/stagexl-0.7.4"},
"unittest":{"version":"0.4.7+1","location":"/Users/gunnar/.pub-cache/hosted/pub.dartlang.org/unittest-0.4.7+1"}}}
Eclipse plugin
Dart Editor for Eclipse 0.4.7.r21548 com.google.dart.eclipse.feature.feature.group dartlang.org
test_runner.dart
import 'package:unittest/unittest.dart';
import 'package:unittest/html_enhanced_config.dart';
import 'ChessColor_test.dart' as color_test;
void main() {
useHtmlEnhancedConfiguration();
group('Enum tests', color_test.main);
}
ChessColor_test.dart
library color_test;
import 'package:unittest/unittest.dart';
void main() {
test('isWhite', () =>
expect(true, WHITE.isWhite())
);
}
A couple of things to try:
Take a look at dart-sdk/lib/async/future.dart. Do you see a Future.value factory constructor? If not, then your SDK is not the right version. I would check this both from the command line and from within the editor.
If you do see it in the SDK, try exiting and restarting the editor. I'm speculating here, but when we saw this once in house, it behaved as though there was a cached copy of the async library that was out of date, and restarting made the issue go way.
I using Dart Editor 0.3.7_r18717 (means the editor is up to date (Feb 2013)
import 'dart:intl';
Shows an error "Cannot find referenced source"
If I import the package via pub
import 'package:intl/intl.dart';
then compiling to JS dart2js fails with some weird errors...
What I want is simply something like this:
final String time = new DateFormat("HH:mm:ss","de").format(new DateTime.now());
It's not clear at all why the locale is needed in such case...
thx
[Update]
OK - I know "weird errors" means nothing - so here is the output if I import the following two packages:
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
String getTime() {
final String time = new DateFormat("HH:mm:ss","en_US").format(new DateTime.now());
//final String time = "20:05:00";
return time;
}
Output:
Running dart2js...
Using snapshot /Developer/dart/dart-sdk/lib/_internal/compiler/implementation/dart2js.dart.snapshot
Wrote /Users/mikemitterer/dart/WebSockets.SAMPLE/web/out/jrelaisui.html_bootstrap.dart.js [410.0kb written in 5.3 seconds]
build.dart --machine --changed=web/jrelaisui.dart
file:/Users/mikemitterer/dart/WebSockets.SAMPLE/build.dart
build.dart returned error code 255
Uncaught Error: NoSuchMethodError : method not found: '_addFromInteger#0x36924d72'
Receiver: null
Arguments: [80]
Stack Trace:
#0 Object.noSuchMethod (dart:core-patch:1737:25)
#1 int.+ (dart:core-patch:1324:33)
#2 Parser.translateCharacter (package:analyzer_experimental/src/generated/parser.dart:4380:167)
#3 Parser.computeStringValue (package:analyzer_experimental/src/generated/parser.dart:376:33)
#4 Parser.parseStringLiteral (package:analyzer_experimental/src/generated/parser.dart:3451:76)
#5 Parser.parsePrimaryExpression (package:analyzer_experimental/src/generated/parser.dart:3163:32)
#6 Parser.parseAssignableExpression (package:analyzer_experimental/src/generated/parser.dart:837:51)
#7 Parser.parsePostfixExpression (package:analyzer_experimental/src/generated/parser.dart:3061:51)
...
Output - Clean Up Source:
build.dart --machine --clean
file:/Users/mikemitterer/dart/HelloWebComponent/build.dart
build.dart returned error code 255
'package:html5lib/src/encoding_parser.dart': Error: line 65 pos 14: class 'EncodingBytes' overrides function 'skip' of super class 'Iterable' with incompatible parameters
String skip([CharPreciate skipChars]) {
^
build.dart --machine --clean
file:/Users/mikemitterer/dart/todomvc/build.dart
build.dart returned error code 255
'package:html5lib/src/encoding_parser.dart': Error: line 65 pos 14: class 'EncodingBytes' overrides function 'skip' of super class 'Iterable' with incompatible parameters
String skip([CharPreciate skipChars]) {
...
Thats what I mean with "weird" :-)
The package syntax is the correct one, this should work:
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
main() {
print(new DateFormat.yMd().format(new DateTime.now()));
}
What "weird errors" are you talking about?
import "dart:intl"; won't work to import it because it's not one of the "core" dart libraries, it has to be imported as a package. The errors you're listing in dart2js don't look like they're coming from internationalization code, but from web_ui and from the analyzer_experimental package. What happens if you comment out the lines that use internationalization and compile using dart2js?