Skip to content

Commit cf0671c

Browse files
authored
Mention JSON format in dart2js args error message (#3414)
For `--define` arguments build_runner will attempt a JSON parse, and treat anything with a format error as a `String`. Parsing as JSON allows for structured content, similar to what can be added in `build.yaml`. Silently falling back to the input as a string avoids requiring extra quotes for the majority of simple options. When the JSON decode fails unexpectedly, the error message can be confusing and does not point to the problem. It's not easy to distinguish between a `build.yaml` with a String value (that never would be parsed as JSON) or command line argument, so we cannot tell for sure if JSON formatting is the problem. The best we can do is point out that it may have failed to parse. Remove the name of the argument from the message, it is already present in the `ArgumentError.toString()`.
1 parent 5e4f4e1 commit cf0671c

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

build_web_compilers/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.2.8-dev
2+
3+
- Mention JSON formatting in error message about dart2js args.
4+
15
## 3.2.7
26

37
- Migrate off deprecated analyzer apis.

build_web_compilers/lib/src/web_entrypoint_builder.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ class WebEntrypointBuilder implements Builder {
9999
}
100100

101101
if (options.config[_dart2jsArgsOption] is! List) {
102-
throw ArgumentError.value(options.config[_dart2jsArgsOption],
103-
_dart2jsArgsOption, 'Expected a list for $_dart2jsArgsOption.');
102+
var message = options.config[_dart2jsArgsOption] is String
103+
? 'There may have been a failure decoding as JSON, expected a list'
104+
: 'Expected a list';
105+
throw ArgumentError.value(
106+
options.config[_dart2jsArgsOption], _dart2jsArgsOption, message);
104107
}
105108
var dart2JsArgs = (options.config[_dart2jsArgsOption] as List?)
106109
?.map((arg) => '$arg')

build_web_compilers/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_web_compilers
2-
version: 3.2.7
2+
version: 3.2.8-dev
33
description: Builder implementations wrapping the dart2js and DDC compilers.
44
repository: https://github.com/dart-lang/build/tree/master/build_web_compilers
55

0 commit comments

Comments
 (0)