Cycle loading state error: LibraryContext.load2.loadBundle

The builder process I’ve been using with no problems is now breaking on watch. That is to say:

  • It completes just fine with pub run build_runner build --delete-conflicting-outputs (though it does warn me about missing required sources, though that has been fine to ignore for months).

    $ pub run build_runner build --delete-conflicting-outputs
    [INFO] Generating build script completed, took 337ms
    [WARNING] The package `edgehead` does not include some required sources in any of its targets (see their build.yaml file).
    The missing sources are:
      - $package$
    [INFO] Reading cached asset graph completed, took 120ms
    [INFO] Checking for updates since last build completed, took 512ms
    [INFO] Running build completed, took 16.0s
    [INFO] Caching finalized dependency graph completed, took 101ms
    [INFO] Succeeded after 16.2s with 43 outputs (250 actions)
    
  • It also completes fine for the initial build of pub run build_runner watch --delete-conflicting-outputs

  • But then, when it’s watching and I change the file, it breaks with the following:

$ pub run build_runner watch --delete-conflicting-outputs
[INFO] Generating build script completed, took 314ms
[WARNING] The package `edgehead` does not include some required sources in any of its targets (see their build.yaml file).
The missing sources are:
  - $package$
[INFO] Setting up file watchers completed, took 4ms
[INFO] Waiting for all file watchers to be ready completed, took 201ms
[INFO] Reading cached asset graph completed, took 122ms
[INFO] Checking for updates since last build completed, took 558ms
[INFO] Running build completed, took 14.8s
[INFO] Caching finalized dependency graph completed, took 126ms
[INFO] Succeeded after 14.9s with 43 outputs (250 actions)
[INFO] ------------------------------------------------------------------------
[INFO] Starting Build
[INFO] Updating asset graph completed, took 3ms
[SEVERE] egamebook_builder:writers_builder on lib/writers_input.dart:

Cycle loading state error
#0      LibraryContext.load2.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:177:32)
dart-lang/build#1      LibraryContext.load2.<anonymous closure> (package:analyzer/src/dart/analysis/library_context.dart:250:17)
dart-lang/build#2      PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:34:15)
dart-lang/build#3      LibraryContext.load2 (package:analyzer/src/dart/analysis/library_context.dart:248:12)
dart-lang/build#4      AnalysisDriver._createLibraryContext.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1504:25)
dart-lang/build#5      _rootRun (dart:async/zone.dart:1190:13)
dart-lang/build#6      _CustomZone.run (dart:async/zone.dart:1093:19)
dart-lang/build#7      _runZoned (dart:async/zone.dart:1630:10)
dart-lang/build#8      runZoned (dart:async/zone.dart:1550:10)
dart-lang/build#9      NullSafetyUnderstandingFlag.enableNullSafetyTypes (package:analyzer/dart/element/null_safety_understanding_flag.dart:42:12)
dart-lang/build#10     AnalysisDriver._createLibraryContext (package:analyzer/src/dart/analysis/driver.dart:1490:33)
dart-lang/build#11     AnalysisDriver._computeUnitElement.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1420:28)
dart-lang/build#12     PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:34:15)
dart-lang/build#13     AnalysisDriver._computeUnitElement (package:analyzer/src/dart/analysis/driver.dart:1418:20)
dart-lang/build#14     AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1006:34)
dart-lang/build#15     AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:1967:24)
<asynchronous suspension>
dart-lang/build#16     AnalysisDriverScheduler.start (package:analyzer/src/dart/analysis/driver.dart:1890:5)
dart-lang/build#17     analysisDriver (package:build_resolvers/src/analysis_driver.dart:62:13)
dart-lang/build#18     AnalyzerResolvers._ensureInitialized.<anonymous closure> (package:build_resolvers/src/resolver.dart:224:26)
<asynchronous suspension>
dart-lang/build#19     AnalyzerResolvers._ensureInitialized.<anonymous closure> (package:build_resolvers/src/resolver.dart)
dart-lang/build#20     AnalyzerResolvers._ensureInitialized (package:build_resolvers/src/resolver.dart:227:6)
dart-lang/build#21     AnalyzerResolvers.get (package:build_resolvers/src/resolver.dart:232:11)
dart-lang/build#22     PerformanceTrackingResolvers.get.<anonymous closure> (package:build_runner_core/src/performance_tracking/performance_tracking_resolvers.dart:19:58)
dart-lang/build#23     _NoOpBuilderActionTracker.trackStage (package:build_runner_core/src/generate/performance_tracker.dart:302:15)
dart-lang/build#24     PerformanceTrackingResolvers.get (package:build_runner_core/src/performance_tracking/performance_tracking_resolvers.dart:19:16)
dart-lang/build#25     BuildStepImpl.resolver (package:build/src/builder/build_step_impl.dart:73:54)
dart-lang/build#26     _Builder.build (package:source_gen/src/builder.dart:68:32)
dart-lang/build#27     runBuilder.buildForInput (package:build/src/generate/run_builder.dart:55:21)
dart-lang/build#28     MappedListIterable.elementAt (dart:_internal/iterable.dart:417:31)
dart-lang/build#29     ListIterator.moveNext (dart:_internal/iterable.dart:343:26)
dart-lang/build#30     Future.wait (dart:async/future.dart:402:26)
dart-lang/build#31     runBuilder.<anonymous closure> (package:build/src/generate/run_builder.dart:61:36)
dart-lang/build#32     _rootRun (dart:async/zone.dart:1190:13)
dart-lang/build#33     _CustomZone.run (dart:async/zone.dart:1093:19)
dart-lang/build#34     _runZoned (dart:async/zone.dart:1630:10)
dart-lang/build#35     runZonedGuarded (dart:async/zone.dart:1618:12)
dart-lang/build#36     runZoned (dart:async/zone.dart:1547:12)
dart-lang/build#37     scopeLogAsync (package:build/src/builder/logging.dart:26:3)
dart-lang/build#38     runBuilder (package:build/src/generate/run_builder.dart:61:9)
dart-lang/build#39     _SingleBuild._runForInput.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:485:19)
dart-lang/build#40     _NoOpBuilderActionTracker.trackStage (package:build_runner_core/src/generate/performance_tracker.dart:302:15)
dart-lang/build#41     _SingleBuild._runForInput.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:483:23)
<asynchronous suspension>
dart-lang/build#42     _SingleBuild._runForInput.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart)
dart-lang/build#43     NoOpTimeTracker.track (package:timing/src/timing.dart:222:44)
dart-lang/build#44     _SingleBuild._runForInput.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:440:22)
dart-lang/build#45     Pool.withResource (package:pool/pool.dart:127:28)
<asynchronous suspension>
dart-lang/build#46     _SingleBuild._runForInput (package:build_runner_core/src/generate/build_impl.dart:436:17)
dart-lang/build#47     _SingleBuild._runBuilder.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:374:38)
dart-lang/build#48     MappedIterator.moveNext (dart:_internal/iterable.dart:392:20)
dart-lang/build#49     Future.wait (dart:async/future.dart:402:26)
dart-lang/build#50     _SingleBuild._runBuilder (package:build_runner_core/src/generate/build_impl.dart:373:36)
dart-lang/build#51     _SingleBuild._runPhases.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:319:20)
<asynchronous suspension>
dart-lang/build#52     _SingleBuild._runPhases.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart)
dart-lang/build#53     _NoOpBuildPerformanceTracker.trackBuildPhase (package:build_runner_core/src/generate/performance_tracker.dart:184:15)
dart-lang/build#54     _SingleBuild._runPhases.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:315:47)
dart-lang/build#55     NoOpTimeTracker.track (package:timing/src/timing.dart:222:44)
dart-lang/build#56     _SingleBuild._runPhases (package:build_runner_core/src/generate/build_impl.dart:309:32)
dart-lang/build#57     logTimedAsync (package:build_runner_core/src/logging/logging.dart:25:30)
dart-lang/build#58     _SingleBuild._safeBuild.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:266:26)
dart-lang/build#59     _rootRun (dart:async/zone.dart:1190:13)
dart-lang/build#60     _CustomZone.run (dart:async/zone.dart:1093:19)
dart-lang/build#61     _runZoned (dart:async/zone.dart:1630:10)
dart-lang/build#62     runZonedGuarded (dart:async/zone.dart:1618:12)
dart-lang/build#63     runZoned (dart:async/zone.dart:1547:12)
dart-lang/build#64     _SingleBuild._safeBuild (package:build_runner_core/src/generate/build_impl.dart:261:5)
dart-lang/build#65     _SingleBuild.run (package:build_runner_core/src/generate/build_impl.dart:208:24)
dart-lang/build#66     BuildImpl.run (package:build_runner_core/src/generate/build_impl.dart:94:56)
dart-lang/build#67     WatchImpl._run.<anonymous closure> (package:build_runner/src/generate/watch_impl.dart:337:14)
<asynchronous suspension>
dart-lang/build#68     WatchImpl._run.<anonymous closure> (package:build_runner/src/generate/watch_impl.dart)
dart-lang/build#69     WatchImpl._run (package:build_runner/src/generate/watch_impl.dart:355:6)
dart-lang/build#70     new WatchImpl (package:build_runner/src/generate/watch_impl.dart:196:20)
dart-lang/build#71     _runWatch (package:build_runner/src/generate/watch_impl.dart:127:5)
dart-lang/build#72     watch (package:build_runner/src/generate/watch_impl.dart:85:15)
dart-lang/build#73     _rootRunUnary (dart:async/zone.dart:1198:47)
dart-lang/build#74     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
dart-lang/build#75     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
dart-lang/build#76     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
dart-lang/build#77     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
dart-lang/build#78     Future._completeWithValue (dart:async/future_impl.dart:529:5)
dart-lang/build#79     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
dart-lang/build#80     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
dart-lang/build#81     BuildOptions.create (package:build_runner_core/src/generate/options.dart)
dart-lang/build#82     _rootRunUnary (dart:async/zone.dart:1198:47)
dart-lang/build#83     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
dart-lang/build#84     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
dart-lang/build#85     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
dart-lang/build#86     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
dart-lang/build#87     Future._completeWithValue (dart:async/future_impl.dart:529:5)
dart-lang/build#88     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
dart-lang/build#89     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
dart-lang/build#90     TargetGraph.forPackageGraph (package:build_runner_core/src/package_graph/target_graph.dart)
dart-lang/build#91     _rootRunUnary (dart:async/zone.dart:1198:47)
dart-lang/build#92     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
dart-lang/build#93     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
dart-lang/build#94     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
dart-lang/build#95     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
dart-lang/build#96     Future._completeWithValue (dart:async/future_impl.dart:529:5)
dart-lang/build#97     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
dart-lang/build#98     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
dart-lang/build#99     _packageBuildConfig (package:build_runner_core/src/package_graph/target_graph.dart)
dart-lang/build#100    _rootRunUnary (dart:async/zone.dart:1198:47)
dart-lang/build#101    _CustomZone.runUnary (dart:async/zone.dart:1100:19)
dart-lang/build#102    _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
dart-lang/build#103    Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
dart-lang/build#104    Future._propagateToListeners (dart:async/future_impl.dart:725:32)
dart-lang/build#105    Future._completeWithValue (dart:async/future_impl.dart:529:5)
dart-lang/build#106    _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
dart-lang/build#107    _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
dart-lang/build#108    BuildConfig.fromBuildConfigDir (package:build_config/src/build_config.dart)
dart-lang/build#109    _rootRunUnary (dart:async/zone.dart:1198:47)
dart-lang/build#110    _CustomZone.runUnary (dart:async/zone.dart:1100:19)
dart-lang/build#111    _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
dart-lang/build#112    Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
dart-lang/build#113    Future._propagateToListeners (dart:async/future_impl.dart:725:32)
dart-lang/build#114    Future._completeWithValue (dart:async/future_impl.dart:529:5)
dart-lang/build#115    Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
dart-lang/build#116    _rootRun (dart:async/zone.dart:1190:13)
dart-lang/build#117    _CustomZone.run (dart:async/zone.dart:1093:19)
dart-lang/build#118    _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
dart-lang/build#119    _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
dart-lang/build#120    _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
dart-lang/build#121    _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
dart-lang/build#122    _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)

I don’t have a minimal repro, but if you’re willing to try it out on the real thing:

  1. git clone https://github.com/filiph/egamebook.git
  2. cd egamebook/edgehead
  3. pub get
  4. pub run build_runner watch --delete-conflicting-outputs
  5. Open any file in assets/text/Knights (e.g. this one) and make a whitespace change, then save

That should trigger the failure.


  • Dart SDK Version (dart --version)

    • Dart SDK version: 2.9.0 (stable) (Fri Jul 31 10:59:48 2020 +0200) on “macos_x64”
  • What package(s) from this repo you are using, and the version (i.e. build_runner 0.7.12)

    • build (transitive) 1.3.0
    • build_runner (direct dev) 1.10.1
  • What builder(s) you are using (or writing yourself). Try to give a short summary of what they do.

    • I’m using my own runners that take text files and transpile them into dart files.
    • I’m also using built_value that runs both on manually-written Dart files as well as on the dart files generated in the previous step.
  • Whether you are using Windows, MacOSX, or Linux (if applicable)

    • MacOSX
  • Any other packages or constraints we should know about

    • You can look at the mono repo and its pubspecs here, but I don’t think there’s anything out of the ordinary.

1 possible answer(s) on “Cycle loading state error: LibraryContext.load2.loadBundle

  1. Yes, this is an analyzer issue, internal exceptions should not happen.
    If this is caused by a client using APIs incorrectly, then the analyzer should report it a a kind of StateError explicitly.
    So, let’s move it.