Describe the bug
When using build_runner 1.10.3 or higher, an InconsistentAnalysisException will frequently be thrown by one random dart file, whenever I run build for the first time in a freshly cloned project. When you run build again, it mostly succeeds.
Example stacktrace:
dart pub run build_runner build
Precompiling executable...
Precompiled build_runner:build_runner.
[INFO] Generating build script completed, took 937ms
[INFO] Creating build script snapshot... completed, took 24.9s
[INFO] Building new asset graph completed, took 1.6s
[INFO] Checking for unexpected pre-existing outputs. completed, took 2ms
[INFO] Generating SDK summary completed, took 5.4s
[WARNING] freezed:freezed on lib/src/models/auth_exception.dart:
Error InconsistentAnalysisException: Requested result might be inconsistent with previously returned results
[WARNING] freezed:freezed on lib/src/models/auth_exception.dart:
#0 AnalysisSessionImpl._checkConsistency (package:analyzer/src/dart/analysis/session.dart:146:7)
#1 AnalysisSessionImpl.getParsedLibraryByElement (package:analyzer/src/dart/analysis/session.dart:93:5)
#2 documentationOfParameter (package:freezed/src/utils.dart:8:12)
#3 new Property.fromParameter (package:freezed/src/templates/concrete_template.dart:399:12)
#4 FreezedGenerator._parseConstructorsNeedsGeneration (package:freezed/src/freezed_generator.dart:473:24)
#5 FreezedGenerator.parseElement (package:freezed/src/freezed_generator.dart:239:9)
#6 ParserGenerator.generate (package:freezed/src/parse_generator.dart:29:22)
#7 _generate (package:source_gen/src/builder.dart:323:33)
<asynchronous suspension>
#8 _Builder._generateForLibrary (package:source_gen/src/builder.dart:84:15)
#9 _Builder.build (package:source_gen/src/builder.dart:76:11)
<asynchronous suspension>
#10 runBuilder.buildForInput (package:build/src/generate/run_builder.dart:55:21)
#11 MappedListIterable.elementAt (dart:_internal/iterable.dart:417:31)
#12 ListIterator.moveNext (dart:_internal/iterable.dart:343:26)
#13 Future.wait (dart:async/future.dart:406:26)
#14 runBuilder.<anonymous closure> (package:build/src/generate/run_builder.dart:61:36)
#15 _rootRun (dart:async/zone.dart:1190:13)
#16 _CustomZone.run (dart:async/zone.dart:1093:19)
#17 _runZoned (dart:async/zone.dart:1630:10)
#18 runZonedGuarded (dart:async/zone.dart:1618:12)
#19 runZoned (dart:async/zone.dart:1547:12)
#20 scopeLogAsync (package:build/src/builder/logging.dart:26:3)
#21 runBuilder (package:build/src/generate/run_builder.dart:61:9)
#22 _SingleBuild._runForInput.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:485:19)
#23 _NoOpBuilderActionTracker.trackStage (package:build_runner_core/src/generate/performance_tracker.dart:302:15)
#24 _SingleBuild._runForInput.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:483:23)
<asynchronous suspension>
#25 _SingleBuild._runForInput.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart)
#26 NoOpTimeTracker.track (package:timing/src/timing.dart:222:44)
#27 _SingleBuild._runForInput.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:440:22)
#28 Pool.withResource (package:pool/pool.dart:127:28)
<asynchronous suspension>
#29 _SingleBuild._runForInput (package:build_runner_core/src/generate/build_impl.dart:436:17)
#30 _SingleBuild._runBuilder.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:374:38)
#31 MappedIterator.moveNext (dart:_internal/iterable.dart:392:20)
#32 Future.wait (dart:async/future.dart:406:26)
#33 _SingleBuild._runBuilder (package:build_runner_core/src/generate/build_impl.dart:373:36)
#34 _SingleBuild._runPhases.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:319:20)
#35 _rootRunUnary (dart:async/zone.dart:1198:47)
#36 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#37 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#38 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#39 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#40 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#41 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
#42 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
#43 _SingleBuild._matchingPrimaryInputs (package:build_runner_core/src/generate/build_impl.dart)
#44 _rootRunUnary (dart:async/zone.dart:1198:47)
#45 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#46 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#47 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#48 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#49 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#50 Future.wait.<anonymous closure> (dart:async/future.dart:414:23)
#51 _rootRunUnary (dart:async/zone.dart:1198:47)
#52 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#53 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#54 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#55 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#56 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#57 Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
#58 _rootRun (dart:async/zone.dart:1190:13)
#59 _CustomZone.run (dart:async/zone.dart:1093:19)
#60 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#61 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#62 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#63 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#64 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#65 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)
[SEVERE] freezed:freezed on lib/src/models/auth_exception.dart:
InconsistentAnalysisException: Requested result might be inconsistent with previously returned results
[INFO] Running build completed, took 20.2s
[INFO] Caching finalized dependency graph completed, took 94ms
[SEVERE] Failed after 20.3s
To Reproduce
I have tried to reproduce the bug in a smaller projekt, but was not able to yet. I have tried it on various machines and with different versions of build_runner. Both 1.10.3 and 1.10.4 fail. See https://github.com/Skycoder42/firebase_auth_rest/actions/runs/347006588 for pipeline results for all 3 operating systems. The file that triggers the error is always a different one, seemingly random.
If you want to reproduce it yourself, you can simply build the project:
git clone https://github.com/Skycoder42/firebase_auth_rest
git reset --hard a4a8f048c30104e9e555f5ccdaecb27438024592
dart pub get
dart pub run build_runner build
Expected behavior
The build should not crash.
Same here
Same here. This might be helpful https://github.com/dart-lang/build/issues/2634#issuecomment-670603224
I'm getting this error all the time not just once.
I was getting the same error. I am using injectable in the same class with freezed.
I solved it by first removing @injectable and running build runner
At that point, there were no more errors.
Then I added @injectable back and everything worked as they should.
I'm also having this issue, with or without injectable.
For information:
I am looking for a fix, but I haven't found any at the moment. The fact that this is random doesn't help.
If someone can search on their own and make a PR, that would be very sweet!
I've published a 0.12.3-dev version that potentially fix this issue
I _think_ that fixes it, but please try and tell me if you have any issue. Due to the exception being random, it is hard to guarantee that the issue is fully resolved.
It indeed seems to be fixed - I rebuilt my previously failing project about 20 times locally and once on each platform in the CI - all worked without problem 馃憤
Chiming in a bit late here - I had a specific commit in my repo that consistently reproduced this issue.
Before 0.12.3-dev I resolved this by renaming the file.
With 0.12.3-dev, renaming is not needed - the issue is completely gone.
Most helpful comment
For information:
I am looking for a fix, but I haven't found any at the moment. The fact that this is random doesn't help.
If someone can search on their own and make a PR, that would be very sweet!