json_serializable.dart
json_serializable.dart copied to clipboard
Cannot handle types defined in Flutter dart:ui
UPDATE: Likely due to and blocked by https://github.com/dart-lang/build/issues/733
Color fields with @JsonKey(fromJson: _colorFromJson, toJson: _colorToJson) annotations fail.
Setup
- json_serializable 0.5.7
- json_annotation 0.2.8
- flutter 0.4.4
Repo
- Use the following code
@JsonSerializable(nullable: true, includeIfNull: false)
class TestClass extends Object with _$TestClassSerializerMixin {
@JsonKey(fromJson: _colorFromJson, toJson: _colorToJson)
Color color;
TestClass();
factory TestClass.fromJson(Map<String, dynamic> jsonMap) => _$TestClassFromJson(jsonMap);
}
Color _colorFromJson(String colorString) {
int intColor = int.tryParse(colorString, radix: 16);
if (intColor == null)
return null;
else
return new Color(intColor);
}
String _colorToJson(Color color) => color.value.toRadixString(16);
- Run
flutter packages pub run build_runner build
Result
Build fails. No usable xxx.g.dart file created. Errors on screen.
[SEVERE] json_serializable on lib/data/xxx.dart:
Error running JsonSerializableGenerator
At least one field has an invalid type: `color`.
package:xxxxxxxx/data/xxxx.dart:63:9
Color color;
^^^^^
Comments
Seems related to functionality in https://github.com/dart-lang/json_serializable/issues/133#issuecomment-387906489 by @kevmoo .
That is super weird.
- Have you run
pub upgradelately? - What is the Dart version when your run
flutter --version(after `Tools).
-
Yes. Ran it again now for goodness. All was already up to date.
Flutter 0.4.4 • channel beta • https://[email protected]/flutter/flutter.git
Framework • revision f9bb4289e9 (5 weeks ago) • 2018-05-11 21:44:54 -0700
Engine • revision 06afdfe54e
Tools • Dart 2.0.0-dev.54.0.flutter-46ab040e58
Try this
> flutter packages pub run build_runner clean
> flutter packages pub run build_runner build --verbose
...and paste the output
Sure.
flutter packages pub run build_runner clean
[INFO] Generating build script...
[INFO] Generating build script completed, took 4.0s
[WARNING] Deleting cache and generated source files.
This shouldn't be necessary for most applications, unless you have made intentional edits to generated files (i.e. for testing). Consider filing a bug at https://github.com/dart-lang/build/issues/new if you are using this to work around an apparent (and reproducible) bug.
[INFO] Cleaning up source outputs...
[INFO] Cleaning up source outputs completed, took 1.3s
[INFO] Cleaning up cache directory...
[INFO] Cleaning up cache directory completed, took 13ms
flutter packages pub run build_runner build --verbose
[INFO] Generating build script...
[INFO] Generating build script completed, took 4.0s
[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Building new asset graph...
[INFO] BuildDefinition:Building new asset graph completed, took 2.1s
[INFO] BuildDefinition:Checking for unexpected pre-existing outputs....
[INFO] BuildDefinition:Checking for unexpected pre-existing outputs. completed, took 24ms
[INFO] Build:Running build...
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[INFO] Heartbeat:12.2s elapsed, 3/20 actions completed.
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[INFO] Heartbeat:15.0s elapsed, 6/20 actions completed.
[INFO] Heartbeat:16.2s elapsed, 6/20 actions completed.
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[INFO] Heartbeat:20.0s elapsed, 6/20 actions completed.
[INFO] Heartbeat:21.1s elapsed, 10/20 actions completed.
[SEVERE] json_serializable on lib/notaproblemredacted.dart:
Unable to resolve asset ID for "dart:ui"
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on test/widget_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on test/widget_test.dart:Running JsonLiteralGenerator - 2 of 2
[SEVERE] json_serializable on lib/redacted.dart:
Error running JsonSerializableGenerator
At least one field has an invalid type: `color`.
package:redactedproblemfile.dart:48:9
Color color;
^^^^^
package:json_serializable/src/utils.dart 148:5 createSortedFieldSet
package:json_serializable/src/generator_helper.dart 94:24 _GeneratorHelper._writeCtor
package:json_serializable/src/generator_helper.dart 67:28 _GeneratorHelper._generate
package:json_serializable/src/generator_helper.dart 32:17 generate
package:json_serializable/src/json_serializable_generator.dart 159:7 JsonSerializableGenerator.generateForAnnotatedElement
package:source_gen/src/generator_for_annotation.dart 40:15 GeneratorForAnnotation.generate.<fn>
dart:async Future.wait
package:source_gen/src/generator_for_annotation.dart 39:34 GeneratorForAnnotation.generate
package:source_gen/src/builder.dart 214:35 _generate
package:source_gen/src/builder.dart 76:15 _Builder._generateForLibrary
package:source_gen/src/builder.dart 67:11 _Builder.build
package:build runBuilder
package:build_runner_core/src/generate/build_impl.dart 424:15 _SingleBuild._runForInput.<fn>
package:build_runner_core/src/generate/performance_tracker.dart 246:73 _NoOpBuilderActionTracker.track
package:build_runner_core/src/generate/build_impl.dart 423:19 _SingleBuild._runForInput
package:build_runner_core/src/generate/build_impl.dart 349:38 _SingleBuild._runBuilder.<fn>
dart:async Future.wait
package:build_runner_core/src/generate/build_impl.dart 348:36 _SingleBuild._runBuilder
package:build_runner_core/src/generate/build_impl.dart 296:32 _SingleBuild._runPhases.<fn>
package:build_runner_core/src/generate/performance_tracker.dart 140:15 _NoOpBuildPerformanceTracker.trackBuildPhase
package:build_runner_core/src/generate/build_impl.dart 292:33 _SingleBuild._runPhases
package:build_runner_core/src/logging/logging.dart 25:30 logTimedAsync
package:build_runner_core/src/generate/build_impl.dart 260:26 _SingleBuild._safeBuild.<fn>
dart:async runZoned
package:build_runner_core/src/generate/build_impl.dart 255:5 _SingleBuild._safeBuild
package:build_runner_core/src/generate/build_impl.dart 185:24 _SingleBuild.run
package:build_runner_core/src/generate/build_impl.dart 89:30 BuildImpl.run
package:build_runner_core/src/generate/build_runner.dart 23:14 BuildRunner.run
package:build_runner BuildCommand.run
package:args/command_runner.dart 194:27 CommandRunner.runCommand
package:args/command_runner.dart 109:29 CommandRunner.run.<fn>
dart:async new Future.sync
package:args/command_runner.dart 109:11 CommandRunner.run
package:build_runner run
.dart_tool\build\entrypoint\build.dart 11:22 main
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redacted.dart:Running JsonLiteralGenerator - 2 of 2
[INFO] Build:Running build completed, took 34.5s
[INFO] Build:Caching finalized dependency graph...
[INFO] Build:Caching finalized dependency graph completed, took 305ms
[INFO] Build:Succeeded after 34.9s with 6 outputs (20 actions)
Where is the Color type defined? Is it in the current package or somewhere else?
Color is a core Flutter class.
At the top of the file having this error, I have the line import 'package:flutter/material.dart';
Somewhere within that core Flutter package it leads to the Color definition in <fluttersdkdir>\bin\cache\pkg\sky_engine\lib\ui\painting.dart
I bet you anything that's the issue. Will look into it. Thanks!
On Wed, Jun 13, 2018 at 6:07 AM Dale Phurrough [email protected] wrote:
Color is a core Flutter library type.
At the top of the file having this error, I have the line import 'package:flutter/material.dart';
Somewhere within that core Flutter package it leads to the Color definition in
\bin\cache\pkg\sky_engine\lib\ui\painting.dart — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dart-lang/json_serializable/issues/236#issuecomment-396930354, or mute the thread https://github.com/notifications/unsubscribe-auth/AABCimPlG-1mDnNdj4OvLPe3jmxKj0mNks5t8Q59gaJpZM4UlYuD .
Thanks for considering. I poked around myself, but haven't gotten my head around everything needed to address it.
I did also look at type helpers and thought of writing a custom one for Color for my app to perhaps get around this issue and enable it globally. Though, I again haven't yet enough combined knowledge of build, dart, and this package to write it and enable it. Though, the helper code itself, like in the recent helper for Uri, doesn't look that difficult.
@diablodale look up the log you sent
[SEVERE] json_serializable on lib/notaproblemredacted.dart:
Unable to resolve asset ID for "dart:ui"
Looking into this now...
I hacked into build_resolver to add a stack there.
@jakemac53 Could this be a bug in build_resolvers? Or pkg:analyzer?
[SEVERE] json_serializable on lib/example.dart:
Unable to resolve asset ID for "dart:ui"
oops
package:build_resolvers/src/resolver.dart 292:24 _AssetUriResolver.resolveAbsolute
package:analyzer/src/context/source.dart 259:34 SourceFactoryImpl._internalResolveUri.<fn>
dart:collection _HashMap.putIfAbsent
package:analyzer/src/context/source.dart 257:38 SourceFactoryImpl._internalResolveUri
package:analyzer/src/context/source.dart 158:14 SourceFactoryImpl.resolveUri
package:analyzer/src/task/dart.dart 3944:36 ParseDartTask._resolveUri
package:analyzer/src/task/dart.dart 3897:23 ParseDartTask._resolveDirective
package:analyzer/src/task/dart.dart 3797:37 ParseDartTask.internalPerform
package:analyzer/src/task/api/model.dart 323:9 AnalysisTask._safelyPerform
package:analyzer/src/task/api/model.dart 222:7 AnalysisTask.perform
package:analyzer/src/task/driver.dart 285:10 AnalysisDriver.performWorkItem
package:analyzer/src/task/driver.dart 110:22 AnalysisDriver.computeResult
package:analyzer/src/context/context.dart 722:14 AnalysisContextImpl.computeResult
package:analyzer/src/context/context.dart 680:14 AnalysisContextImpl.computeKindOf
package:build_resolvers/src/resolver.dart 99:16 AnalyzerResolver._isLibrary
package:build_resolvers/src/resolver.dart 95:30 AnalyzerResolver.isLibrary
package:build_resolvers/src/resolver.dart 61:56 PerActionResolver.isLibrary
package:build _DelayedResolver.isLibrary
package:source_gen/src/builder.dart 65:25 _Builder.build
package:build runBuilder
package:build_runner_core/src/generate/build_impl.dart 424:15 _SingleBuild._runForInput.<fn>
package:build_runner_core/src/generate/performance_tracker.dart 246:73 _NoOpBuilderActionTracker.track
package:build_runner_core/src/generate/build_impl.dart 423:19 _SingleBuild._runForInput
package:build_runner_core/src/generate/build_impl.dart 349:38 _SingleBuild._runBuilder.<fn>
dart:async Future.wait
package:build_runner_core/src/generate/build_impl.dart 348:36 _SingleBuild._runBuilder
package:build_runner_core/src/generate/build_impl.dart 296:32 _SingleBuild._runPhases.<fn>
package:build_runner_core/src/generate/performance_tracker.dart 140:15 _NoOpBuildPerformanceTracker.trackBuildPhase
package:build_runner_core/src/generate/build_impl.dart 292:33 _SingleBuild._runPhases
package:build_runner_core/src/logging/logging.dart 25:30 logTimedAsync
package:build_runner_core/src/generate/build_impl.dart 260:26 _SingleBuild._safeBuild.<fn>
dart:async runZoned
package:build_runner_core/src/generate/build_impl.dart 255:5 _SingleBuild._safeBuild
package:build_runner_core/src/generate/build_impl.dart 185:24 _SingleBuild.run
package:build_runner_core/src/generate/build_impl.dart 89:30 BuildImpl.run
package:build_runner WatchCommand.run
package:args/command_runner.dart 194:27 CommandRunner.runCommand
package:args/command_runner.dart 109:29 CommandRunner.run.<fn>
dart:async new Future.sync
package:args/command_runner.dart 109:11 CommandRunner.run
package:build_runner run
.dart_tool/build/entrypoint/build.dart 11:22 main
Here's the crux, it seems - https://github.com/dart-lang/build/issues/733
That is a known issue. As in https://github.com/google/built_value.dart/issues/282
That specific error has always been there for me. And it caused no harm to any generated files. I can fully use json_serializable and ignore that error. FYI, also that error comes from a separate dart file than the Color example I gave.
Ahh, I see you typing above. This is the first time that I have defining a custom to/fromJson handler for a Flutter type. Other times I have used types outside Flutter.
I might get something similar to work by defining a private field and then custom get/setters. I did that with DateTime because I wanted my DateTime to appear differently than the current DateTime typehandler.
That'd likely be a good way to handle this...
On Wed, Jun 13, 2018 at 10:18 AM Dale Phurrough [email protected] wrote:
I might get something similar to work by defining a private field and then custom get/setters. I did that with DateTime because I wanted my DateTime to appear differently than the current DateTime typehandler.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dart-lang/json_serializable/issues/236#issuecomment-397017263, or mute the thread https://github.com/notifications/unsubscribe-auth/AABCit8faKD0X2qLQ2vvtCLdqxXN64fcks5t8UlsgaJpZM4UlYuD .
Workaround fail. :-/ I've found that @JsonKey(ignore: true) isn't fully ignoring fields and methods.
@JsonKey(ignore: true)
Color color;
@JsonKey(name: "color")
String get colorString => _colorToJson(this.color);
@JsonKey(name: "color")
set colorString(String value) => _colorFromJson(value);
It continues to result in the same error At least one field has an invalid type: color error.
Perhaps this is a separate issue with the ignore annotation exposed through my workaround attempt?
I even tried a workaround^2. It failed with similar At least one field has an invalid type: _color, color.
@JsonKey(ignore: true)
Color _color;
@JsonKey(ignore: true)
Color get color => this._color;
@JsonKey(ignore: true)
set color(Color value) => this._color = value;
@JsonKey(name: "color")
String get colorString => _colorToJson(this._color);
@JsonKey(name: "color")
set colorString(String value) => this._color = _colorFromJson(value);
I have a plan to fix this here. Thanks for your patience...
On Wed, Jun 13, 2018 at 11:41 AM Dale Phurrough [email protected] wrote:
Workaround fail. :-/ I've found that @JsonKey(ignore: true) isn't fully ignoring fields and methods.
@JsonKey(ignore: true)Color color; @JsonKey(name: "color")String get colorString => _colorToJson(this.color);@JsonKey(name: "color")set colorString(String value) => _colorFromJson(value);
It continues to result in the same error At least one field has an invalid type: color error. Perhaps this is a separate issue with the ignore annotation exposed through my workaround attempt?
I even tried a workaround^2. It failed with similar At least one field has an invalid type: _color, color.
@JsonKey(ignore: true)Color _color; @JsonKey(ignore: true)Color get color => this._color;@JsonKey(ignore: true)set color(Color value) => this._color = value; @JsonKey(name: "color")String get colorString => _colorToJson(this._color);@JsonKey(name: "color")set colorString(String value) => this._color = _colorFromJson(value);
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dart-lang/json_serializable/issues/236#issuecomment-397043495, or mute the thread https://github.com/notifications/unsubscribe-auth/AABCit30K2PTZy-OIsUbgOWCwyhzdusZks5t8VzggaJpZM4UlYuD .
PR out w/ a fix (work-around) https://github.com/dart-lang/json_serializable/pull/243
Tested https://github.com/dart-lang/json_serializable/pull/243 which was included in v0.5.8 with my scenario of Color...
I get generated code that works :-) Thanks!
Two oddities:
- I continue to get warnings during build runner on that
Colorfield. - In the generated mixin code, that field has a getter with
dynamicrather thanColor
abstract class _$MyObjectSerializerMixin {
dynamic get color;
Great to hear it works. Both oddities are by design. #1 is just being super clear that the type is weird. #2 is because – well – there's no way to do better. ;-)
On Sat, Jun 23, 2018 at 6:47 AM Dale Phurrough [email protected] wrote:
Tested #243 https://github.com/dart-lang/json_serializable/pull/243 which was included in v0.5.8 with my scenario of Color...
I get generated code that works :-) Thanks!
Two oddities:
- I continue to get warnings during build runner on that Color field.
- In the generated mixin code, that field has a getter with dynamic rather than Color
abstract class _$MyObjectSerializerMixin { dynamic get color;
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/dart-lang/json_serializable/issues/236#issuecomment-399679632, or mute the thread https://github.com/notifications/unsubscribe-auth/AABCilozsbkZLekhUb5sNfs9nDSfdcCdks5t_kbVgaJpZM4UlYuD .
Hi. Unfortunately, there is a regression in that the workaround you released above is no longer working after I changed to the flutter dev channel and upgraded several packages.
It again fails to generate code for a source file that uses Color from dart:ui.
Setup
Flutter 0.5.8 • channel dev • https://[email protected]/flutter/flutter.git Framework • revision e4b989bf3d (8 days ago) • 2018-08-09 09:45:44 -0700 Engine • revision 3777931801 Tools • Dart 2.0.0-dev.69.5.flutter-eab492385c build_runner v0.10.1+1 json_serializable v1.1.0 json_annotation v1.1.0
Repro
- flutter packages pub run build_runner
- flutter clean
- flutter packages pub run build_runner build
- flutter packages pub run build_runner build --verbose
Result
No tag.g.dart file is created for the source file that uses Color from dart:ui
[INFO] Generating build script...
[INFO] Generating build script completed, took 4.8s
[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 2.5s
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 19ms
[INFO] Running build...
[INFO] 13.3s elapsed, 1/16 actions completed.
[INFO] 14.4s elapsed, 1/17 actions completed.
[INFO] 15.5s elapsed, 1/17 actions completed.
[INFO] 16.9s elapsed, 1/17 actions completed.
[INFO] 18.0s elapsed, 1/17 actions completed.
[INFO] 19.0s elapsed, 1/17 actions completed.
[INFO] 20.0s elapsed, 1/17 actions completed.
[INFO] 21.3s elapsed, 1/17 actions completed.
[INFO] 22.4s elapsed, 1/17 actions completed.
[INFO] 23.4s elapsed, 1/17 actions completed.
[WARNING] No actions completed for 16.6s, waiting on:
- json_serializable on test/redacted.dart
- json_serializable on lib/redacted.dart
- json_serializable on lib/data/redacted.dart
- json_serializable on lib/data/redacted.dart
- json_serializable on lib/data/redacted.dart
.. and 11 more
[INFO] 31.0s elapsed, 5/17 actions completed.
[SEVERE] json_serializable on lib/data/tag.dart:
Unable to resolve asset ID for "dart:ui"
[WARNING] json_serializable on lib/data/tag.dart:
This element has an undefined type. It may causes issues when generated code.
package:redacted/data/tag.dart:68:9
Color color;
^^^^^
[WARNING] json_serializable on lib/data/tag.dart:
This element has an undefined type. It may causes issues when generated code.
package:redacted/data/tag.dart:98:10
this.color,
^^^^^
[INFO] 48.8s elapsed, 12/17 actions completed.
[INFO] 50.4s elapsed, 17/17 actions completed.
[INFO] 51.4s elapsed, 21/21 actions completed.
[INFO] 54.6s elapsed, 39/46 actions completed.
[INFO] Running build completed, took 55.1s
[INFO] Caching finalized dependency graph...
[INFO] 56.2s elapsed, 67/67 actions completed.
[INFO] Caching finalized dependency graph completed, took 1.1s
[SEVERE] Failed after 56.3s
pub finished with exit code 1
[INFO] Generating build script...
[INFO] Generating build script completed, took 4.3s
[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Reading cached asset graph...
[INFO] BuildDefinition:Reading cached asset graph completed, took 1.0s
[INFO] BuildDefinition:Checking for updates since last build...
[INFO] BuildDefinition:Checking for updates since last build completed, took 2.7s
[INFO] Build:Running build...
[INFO] Build:Running build completed, took 219ms
[INFO] Build:Caching finalized dependency graph...
[INFO] Build:Caching finalized dependency graph completed, took 340ms
[SEVERE] json_serializable on lib/data/tag.dart (cached):
Unable to resolve asset ID for "dart:ui"
[SEVERE] Build:
Failed after 685ms
pub finished with exit code 1
#0 throwToolExit (package:flutter_tools/src/base/common.dart:26:3)
#1 pubInteractively (package:flutter_tools/src/dart/pub.dart:185:5)
<asynchronous suspension>
#2 PackagesPassthroughCommand.runCommand (package:flutter_tools/src/commands/packages.dart:142:32)
#3 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:348:18)
#4 _asyncThenWrapperHelper.<anonymous closure> (dart:async/runtime/libasync_patch.dart:77:64)
#5 _rootRunUnary (dart:async/zone.dart:1132:38)
#6 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#7 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#8 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#9 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#10 Future._complete (dart:async/future_impl.dart:476:7)
#11 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#12 _AsyncAwaitCompleter.complete.<anonymous closure> (dart:async/runtime/libasync_patch.dart:33:20)
#13 _rootRun (dart:async/zone.dart:1124:13)
#14 _CustomZone.run (dart:async/zone.dart:1021:19)
#15 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
#16 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#17 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#18 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:114:13)
#19 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:170:5)
Workaround for the workaround
I can partially upgrade the json packages and the dart:ui workaround will work. The following combination of versions does not have the regression. Flutter continues to be on the dev channel.
build_runner 0.9.2 json_serializable 0.5.8+1 json_annotation 0.2.9+1
Would you run w/ --verbose so I can see the stack trace?
On Fri, Aug 17, 2018 at 7:18 PM Dale Phurrough [email protected] wrote:
Hi. Unfortunately, there is a regression in that the workaround you released above is no longer working after I changed to the flutter dev channel and upgraded several packages. It again fails to generate code for a source file that uses Color from dart:ui. Setup
Flutter 0.5.8 • channel dev • https://[email protected]/flutter/flutter.git Framework • revision e4b989bf3d (8 days ago) • 2018-08-09 09:45:44 -0700 Engine • revision 3777931801 Tools • Dart 2.0.0-dev.69.5.flutter-eab492385c build_runner v0.10.1+1 json_serializable v1.1.0 json_annotation v1.1.0 Repro
- flutter packages pub run build_runner
- flutter clean
- flutter packages pub run build_runner build
- flutter packages pub run build_runner build --verbose
Result
No tag.g.dart file is created for the source file that uses Color from dart:ui
[INFO] Generating build script... [INFO] Generating build script completed, took 4.8s
[INFO] Initializing inputs [INFO] Building new asset graph... [INFO] Building new asset graph completed, took 2.5s
[INFO] Checking for unexpected pre-existing outputs.... [INFO] Checking for unexpected pre-existing outputs. completed, took 19ms
[INFO] Running build... [INFO] 13.3s elapsed, 1/16 actions completed. [INFO] 14.4s elapsed, 1/17 actions completed. [INFO] 15.5s elapsed, 1/17 actions completed. [INFO] 16.9s elapsed, 1/17 actions completed. [INFO] 18.0s elapsed, 1/17 actions completed. [INFO] 19.0s elapsed, 1/17 actions completed. [INFO] 20.0s elapsed, 1/17 actions completed. [INFO] 21.3s elapsed, 1/17 actions completed. [INFO] 22.4s elapsed, 1/17 actions completed. [INFO] 23.4s elapsed, 1/17 actions completed. [WARNING] No actions completed for 16.6s, waiting on:
- json_serializable on test/redacted.dart
- json_serializable on lib/redacted.dart
- json_serializable on lib/data/redacted.dart
- json_serializable on lib/data/redacted.dart
- json_serializable on lib/data/redacted.dart .. and 11 more
[INFO] 31.0s elapsed, 5/17 actions completed. [SEVERE] json_serializable on lib/data/tag.dart: Unable to resolve asset ID for "dart:ui" [WARNING] json_serializable on lib/data/tag.dart: This element has an undefined type. It may causes issues when generated code. package:redacted/data/tag.dart:68:9 Color color; ^^^^^ [WARNING] json_serializable on lib/data/tag.dart: This element has an undefined type. It may causes issues when generated code. package:redacted/data/tag.dart:98:10 this.color, ^^^^^ [INFO] 48.8s elapsed, 12/17 actions completed. [INFO] 50.4s elapsed, 17/17 actions completed. [INFO] 51.4s elapsed, 21/21 actions completed. [INFO] 54.6s elapsed, 39/46 actions completed. [INFO] Running build completed, took 55.1s
[INFO] Caching finalized dependency graph... [INFO] 56.2s elapsed, 67/67 actions completed. [INFO] Caching finalized dependency graph completed, took 1.1s
[SEVERE] Failed after 56.3s pub finished with exit code 1
[INFO] Generating build script... [INFO] Generating build script completed, took 4.3s [INFO] BuildDefinition:Initializing inputs [INFO] BuildDefinition:Reading cached asset graph... [INFO] BuildDefinition:Reading cached asset graph completed, took 1.0s
[INFO] BuildDefinition:Checking for updates since last build... [INFO] BuildDefinition:Checking for updates since last build completed, took 2.7s
[INFO] Build:Running build... [INFO] Build:Running build completed, took 219ms
[INFO] Build:Caching finalized dependency graph... [INFO] Build:Caching finalized dependency graph completed, took 340ms
[SEVERE] json_serializable on lib/data/tag.dart (cached): Unable to resolve asset ID for "dart:ui"
[SEVERE] Build: Failed after 685ms pub finished with exit code 1
#0 throwToolExit (package:flutter_tools/src/base/common.dart:26:3) #1 pubInteractively (package:flutter_tools/src/dart/pub.dart:185:5)
#2 PackagesPassthroughCommand.runCommand (package:flutter_tools/src/commands/packages.dart:142:32) #3 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:348:18) #4 _asyncThenWrapperHelper. (dart:async/runtime/libasync_patch.dart:77:64) #5 _rootRunUnary (dart:async/zone.dart:1132:38) #6 _CustomZone.runUnary (dart:async/zone.dart:1029:19) #7 _FutureListener.handleValue (dart:async/future_impl.dart:129:18) #8 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45) #9 Future._propagateToListeners (dart:async/future_impl.dart:671:32) #10 Future._complete (dart:async/future_impl.dart:476:7) #11 _SyncCompleter.complete (dart:async/future_impl.dart:51:12) #12 _AsyncAwaitCompleter.complete. (dart:async/runtime/libasync_patch.dart:33:20) #13 _rootRun (dart:async/zone.dart:1124:13) #14 _CustomZone.run (dart:async/zone.dart:1021:19) #15 _CustomZone.bindCallback. (dart:async/zone.dart:947:23) #16 _microtaskLoop (dart:async/schedule_microtask.dart:41:21) #17 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5) #18 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:114:13) #19 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:170:5) — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/dart-lang/json_serializable/issues/236#issuecomment-414026000, or mute the thread https://github.com/notifications/unsubscribe-auth/AABCil4M2bZv8QSqWuakmQommSDXRCkNks5uR3ltgaJpZM4UlYuD .
That is with --verbose. It is the 2nd code block.
Darn. Was hoping to see a stack around
[SEVERE] json_serializable on lib/data/tag.dart:
Unable to resolve asset ID for "dart:ui"
Ah. Do me a favor. Run:
flutter packages pub run build_runner clean
flutter packages pub run build_runner build --verbose
In current working state of older versions, won't be helpful. I would need to reinstall the failing package versions. Though what you see in the two blocks above had been flutter and buildrunner cleaned. I did that as part of my troubleshooting before coming back to this bug.
To be clear are you asking the following?
- build_runner clean (I've discovered this needs to be done before switching versions, otherwise, the clean of the new version faults itself)
- flutter clean
- go back to the failing versions
- build_runner clean
- build_runner build --verbose
If possible, please.
Setup
Successfully generating all *.g.dart files with: build_runner 0.9.2 json_serializable 0.5.8+1 json_annotation 0.2.9+1
Repro
flutter packages pub run build_runner cleanflutter clean- Edited
pubspec.yamland changed dev dependency tojson_serializable: ^1.1.0 flutter packages get- Verified that the following are installed: build_runner 0.9.2 json_serializable 1.1.0 json_annotation 1.1.0
flutter packages pub run build_runner cleanflutter packages pub run build_runner build --verbose
Results
No tag.g.dart file was generated. Other *.g.dart files were generated.
C:\njs\redact1>flutter packages pub run build_runner clean
[INFO] Generating build script...
[INFO] Generating build script completed, took 4.3s
[WARNING] Deleting cache and generated source files.
This shouldn't be necessary for most applications, unless you have made intentional edits to generated files (i.e. for testing). Consider filing a bug at https://github.com/dart-lang/build/issues/new if you are using this to work around an apparent (and reproducible) bug.
[INFO] Cleaning up source outputs...
[INFO] Cleaning up source outputs completed, took 1.6s
[INFO] Cleaning up cache directory...
[INFO] Cleaning up cache directory completed, took 23ms
C:\njs\redact1>flutter clean
Deleting 'build\'.
C:\njs\redact1>flutter packages pub run build_runner clean
[INFO] Generating build script...
[INFO] Generating build script completed, took 4.5s
[WARNING] Deleting cache and generated source files.
This shouldn't be necessary for most applications, unless you have made intentional edits to generated files (i.e. for testing). Consider filing a bug at https://github.com/dart-lang/build/issues/new if you are using this to work around an apparent (and reproducible) bug.
[INFO] Cleaning up source outputs...
[WARNING] No asset graph found, skipping generated to source file cleanup
[INFO] Cleaning up source outputs completed, took 407ms
[INFO] Cleaning up cache directory...
[INFO] Cleaning up cache directory completed, took 55ms
C:\njs\redact1>flutter packages pub run build_runner build --verbose
[INFO] Generating build script...
[INFO] Generating build script completed, took 5.4s
[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Building new asset graph...
[INFO] BuildDefinition:Building new asset graph completed, took 2.7s
[INFO] BuildDefinition:Checking for unexpected pre-existing outputs....
[INFO] BuildDefinition:Checking for unexpected pre-existing outputs. completed, took 16ms
[INFO] Build:Running build...
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[INFO] Heartbeat:16.2s elapsed, 2/31 actions completed.
[INFO] Heartbeat:17.3s elapsed, 2/31 actions completed.
[INFO] Heartbeat:18.4s elapsed, 2/31 actions completed.
[INFO] Heartbeat:19.5s elapsed, 2/31 actions completed.
[FINE] json_serializable on lib/l10n/messages_all.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/l10n/messages_de.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/l10n/messages_es.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/l10n/messages_all.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/l10n/messages_de.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/l10n/messages_es.dart:Running JsonLiteralGenerator - 2 of 2
[INFO] Heartbeat:24.7s elapsed, 5/31 actions completed.
[INFO] Heartbeat:26.0s elapsed, 5/31 actions completed.
[INFO] Heartbeat:27.0s elapsed, 5/31 actions completed.
[INFO] Heartbeat:28.0s elapsed, 5/31 actions completed.
[INFO] Heartbeat:29.0s elapsed, 5/31 actions completed.
[INFO] Heartbeat:30.1s elapsed, 5/31 actions completed.
[INFO] Heartbeat:31.3s elapsed, 5/31 actions completed.
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[SEVERE] json_serializable on lib/data/tag.dart:
Unable to resolve asset ID for "dart:ui"
[FINE] json_serializable on test/widget_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/data/tag.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on test/widget_test.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[WARNING] json_serializable on lib/data/tag.dart:
This element has an undefined type. It may causes issues when generated code.
package:redact/data/tag.dart:69:9
Color color;
^^^^^
[WARNING] json_serializable on lib/data/tag.dart:
This element has an undefined type. It may causes issues when generated code.
package:redact/data/tag.dart:99:10
this.color,
^^^^^
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/data/tag.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable on lib/redact.dart:Running JsonLiteralGenerator - 2 of 2
[INFO] Heartbeat:59.8s elapsed, 55/62 actions completed.
[INFO] Build:Running build completed, took 1m 0s
[INFO] Build:Caching finalized dependency graph...
[INFO] Build:Caching finalized dependency graph completed, took 497ms
[SEVERE] Build:
Failed after 1m 0s
pub finished with exit code 1
#0 throwToolExit (package:flutter_tools/src/base/common.dart:26:3)
#1 pubInteractively (package:flutter_tools/src/dart/pub.dart:185:5)
<asynchronous suspension>
#2 PackagesPassthroughCommand.runCommand (package:flutter_tools/src/commands/packages.dart:142:32)
#3 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:348:18)
#4 _asyncThenWrapperHelper.<anonymous closure> (dart:async/runtime/libasync_patch.dart:77:64)
#5 _rootRunUnary (dart:async/zone.dart:1132:38)
#6 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#7 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#8 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#9 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#10 Future._complete (dart:async/future_impl.dart:476:7)
#11 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#12 _AsyncAwaitCompleter.complete.<anonymous closure> (dart:async/runtime/libasync_patch.dart:33:20)
#13 _rootRun (dart:async/zone.dart:1124:13)
#14 _CustomZone.run (dart:async/zone.dart:1021:19)
#15 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
#16 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#17 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#18 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:114:13)
#19 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:170:5)
Figured it out
- unfound assets cause severe warnings
https://github.com/dart-lang/build/blob/81082de9aed7e4af4945de6d0381d09198593465/build_resolvers/lib/src/resolver.dart#L299-L302
- build_runner now fails builds with severe log entries - as of ^0.9.0
https://github.com/dart-lang/build/commit/c5513e2
So we need to fix one of those. I'd probably vote for fixing the first.
Thoughts, @natebosch @jakemac53 ?
See the assert at the top of that method.... https://github.com/dart-lang/build/blob/81082de9aed7e4af4945de6d0381d09198593465/build_resolvers/lib/src/resolver.dart#L292
We aren't expecting to get called for any dart: uris here. My best guess is that this is actually an analyzer bug, where it doesn't invoke that method for any other dart: uris but does for this one somehow?