Running: flutter packages pub run build_runner build
Lately, I get this error:
[WARNING] No actions completed for 15.1s, waiting on:
- moor_generator:moor_generator on test/widget_test.dart
- moor_generator:moor_generator on lib/choose_icon.dart
- moor_generator:moor_generator on lib/db_classes.dart
.. and 11 more
moor_generator:moor_generator on lib/db_classes.dart:
Error running DaoGenerator
InconsistentAnalysisException: Requested result might be inconsistent with previously returned results
I tried the commands flutter clean and then -> Packages get and -> Packages update
But the error persists
Thanks for the report. I think this is some kind of bug in Dart's build system or the analyzer (see also https://github.com/dart-lang/build/issues/2634).
Moor 3.0 will have an opt-in workaround that seems to circumvent the problem, at the cost of making builds slightly slower. You could try using the beta version and enable the eagerly_load_dart_ast build option.
I did, unfortunately, the beta gave me other errors:
Error: No named parameter with the name 'orReplace'.
So, after building with the beta I switched back to the production one, built again and the error was gone.
Unfortunately, the problem came back, and now this temporary fix(to go in beta and go back) doesn't work anymore. I am unable to build my app, any workaround?
I've hit a problem like this today when creating new methods for the database.
In one case, deleting new method, rebuilding, getting method back and rebuilding again somehow helped. In the other, my function's name was too generic, creating a conflict.
I've faced the same issue. Removing all generated classes and flutter clean did the job for me.
I had the same issue, and removing the mode: InsertModeOrReplace made the build to finish.
My workaround is to move all non-table and non-database classes to elsewhere. However, I would like to keep my composite data classes along with the database in a single file.
In moor 3.0, I've added the eagerly_load_dart_ast builder option, which should fix this problem.
I still think this is something the build system should take care of. Other packages like reflectable ran into similar problems (https://github.com/dart-lang/build/issues/2634), but it looks like an equivalent of the eagerly_load_dart_ast didn't work for them.
If you run into this problem, can you try enabling that option and let me know if that fixes it or not?
Tried to set the eagerly_load_dart_ast like this:
targets:
$default:
builders:
moor_generator:
options:
eagerly_load_dart_ast: true
Still getting errors when generating the files, even if I delete all .g files, do a flutter clean and run flutter packages pub run build_runner build I still get errors.
I get this error randomly. Sometimes it breaks my code because it doesn't generate some of my dao files and sometimes it generates everything even with the error. I literally just keep trying the following 3 commands until i get the files generated:
1) flutter clean
2) flutter get pub
3 flutter packages pub run build_runner build --delete-conflicting-outputs
In some cases, maybe it's just a coincidence, I found that using relative path imports rather than package imports helped. It seemed that if I use package imports (the database dart file into my dao files, the table into the dao file, or dao and table dart files into the database file) then the code generation fails "consistently" (in quotes because I'm not sure that the success I got after changing the imports was just a random success or related to the actual change, the inconsistency makes it difficult to determine that). But once I changed to relative imports, I seem to have a higher success rate with files being generated (not necessary the code generation running successfully).
I'm getting a similar problem with a completely different library
https://github.com/dart-lang/build/issues/2689
Have you tried renaming the files? For me, if these problems are the same...
However, if I do a pub build again after that it often fails, very frustrating but I can sometimes continue now
(could be unrelated but may be the same underlying issue)
Curiously, If I duplicate the project and delete almost everything except the db file, that I leave untouched, it doesn't happen again. The actions go down from 16 to 5 and it builds.
I've temporary solved the issue by using a small bash script, while waiting for real fix:
find ./ -type f -name "*.g.dart" -delete
flutter clean
flutter pub get
flutter packages pub run build_runner build --delete-conflicting-outputs
Just to update my last comment, since my upgrade to 3.0, setting the eagerly_load_dart_ast and doing the build_runner run for the first time with no errors, it never happened again. It's been like 5 days now and I've used alot.
I am also seeing this from time to time after model changes. Only cleaning build_runner/flutter and regenerating everything works in those cases. eagerly_load_dart_ast didn't seem to have an effect.
Just some minutes later and I got the error again rs, so it continue to happens.
Coming from a completely different code generation package that uses build_runner. Probably a flutter or build_runner problem.
@simolus3 There is nothing else to try? Every time I try to change something from some table, It takes me more than 20 min trying to get all .g files working...
Today after a multitude of attempts I couldn't make it works even once, then I realized I made an error. I didn't insert the new table's name in:
@UseMoor(tables: [TableName1, TableName2, ...])
I don't think it is the full problem, but maybe it is a clue or just a separate error that needs its own text error to debug.
If you get this error, can you please try to run the build with pub run build_runner build -v for more information where this happens?
In my understanding, this can happen when multiple builders use the analyzer concurrently and it looks like builders need to guard against this now. Having a stacktrace here would help to spot the parts in moor_generator that need adoptions.
@simolus3 is this the output you were after? Renaming the file and rerunning solves it, until the next occurence.
~/Documents/Mega/dev/main/flutter/wad19worktrees/wad19/assemblies/wad_front_end_logic $ pub run build_runner build -v
[INFO] Generating build script completed, took 296ms
[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Reading cached asset graph...
[INFO] BuildDefinition:Reading cached asset graph completed, took 88ms
[INFO] BuildDefinition:Checking for updates since last build...
[INFO] BuildDefinition:Checking for updates since last build completed, took 513ms
[INFO] Build:Running build...
[INFO] Heartbeat:1.3s elapsed, 0/2 actions completed.
[FINE] mock_creator_generator:mock_creator on lib/selectors/LessonDetailSel.dart:Running MockCreatorGenerator
[FINE] mock_creator_generator:mock_creator on test/selectors/lessonDetailSel_test.dart:Running MockCreatorGenerator
[FINE] typedef_for_fn_generator:typedef_for_fn on test/selectors/lessonDetailSel_test.dart:Running TypedefForFnGenerator
[FINE] typedef_for_fn_generator:typedef_for_fn on lib/selectors/LessonDetailSel.dart:Running TypedefForFnGenerator
[FINE] value_t2_generator:value_t2 on test/selectors/lessonDetailSel_test.dart:Running ValueT2Generator
[FINE] value_t2_generator:value_t2 on lib/selectors/LessonDetailSel.dart:Running ValueT2Generator
[INFO] Build:Running build completed, took 3.4s
[INFO] Build:Caching finalized dependency graph...
[INFO] Build:Caching finalized dependency graph completed, took 43ms
[SEVERE] mock_creator_generator:mock_creator on lib/logic/getFileForType_.dart (cached):
Error running MockCreatorGenerator
InconsistentAnalysisException: Requested result might be inconsistent with previously returned results
package:analyzer/src/dart/analysis/session.dart 202:7 AnalysisSessionImpl._checkConsistency
package:analyzer/src/dart/analysis/session.dart 169:5 AnalysisSessionImpl.getResolvedLibraryByElement
package:mock_creator_generator/src/MockCreatorGenerator.dart 56:28 MockCreatorGenerator.generateForAnnotatedElement
package:mock_creator_generator/src/GeneratorForAnnotationX.dart 47:30 GeneratorForAnnotationX.generate
package:source_gen/src/builder.dart 298:35 _generate
package:source_gen/src/builder.dart 79:15 _Builder._generateForLibrary
package:source_gen/src/builder.dart 71:11 _Builder.build
package:build runBuilder
package:build_runner_core/src/generate/build_impl.dart 487:19 _SingleBuild._runForInput.<fn>.<fn>.<fn>
package:build_runner_core/src/generate/performance_tracker.dart 300:15 _NoOpBuilderActionTracker.trackStage
package:build_runner_core/src/generate/build_impl.dart 485:23 _SingleBuild._runForInput.<fn>.<fn>
package:build_runner_core/src/generate/build_impl.dart _SingleBuild._runForInput.<fn>.<fn>
package:timing/src/timing.dart 222:44 NoOpTimeTracker.track
package:build_runner_core/src/generate/build_impl.dart 442:22 _SingleBuild._runForInput.<fn>
package:pool/pool.dart 127:28 Pool.withResource
package:build_runner_core/src/generate/build_impl.dart 438:17 _SingleBuild._runForInput
package:build_runner_core/src/generate/build_impl.dart 376:38 _SingleBuild._runBuilder.<fn>
dart:async Future.wait
package:build_runner_core/src/generate/build_impl.dart 375:36 _SingleBuild._runBuilder
package:build_runner_core/src/generate/build_impl.dart 321:20 _SingleBuild._runPhases.<fn>.<fn>
dart:async _completeOnAsyncReturn
package:build_runner_core/src/generate/build_impl.dart _SingleBuild._matchingPrimaryInputs
[SEVERE] Build:
Failed after 3.5s
I created this analysis_err_fix that renames the file, runs build, renames the file back; seems a bit crazy but it means this error isn't so much of a problem now locally (although I can't resolve my server build problems).
https://github.com/atreeon/value_t2/tree/master/clear_dirs/bin
@atreeon The error you posted is unrelated to moor.
You can fix your builder by changing this line. It looks like you're not using the resolvedLibrary at all so I'd recommend to just return sb.toString() directly without calling getResolvedLibraryByElement.
In general, you need to expect that element.session.anyMethod() can throw an InconsistentAnalysisException at any time. In that case, you need to obtain a new AnalysisSession and LibraryElement by using the build resolver.
Am having same proble
@simolus3 I redirected both stdout and stderr to the attached file. I hope this helps. Let me know if there's anything else that I can do to help fix this issue as it is the single most annoying problem with moor right now. (I'm not familiar with build runner nor the entire code generation process in dart so my abilities are unfortunately limited).
@majdi21 Thanks for the report! That problem might be fixed on the current beta version of the generator. Can you try to add this to your pubspec, run flutter packages get and see if it fixes the problem?
dependency_overrides:
moor_generator:
git:
url: https://github.com/simolus3/moor.git
ref: beta
path: moor_generator
sqlparser:
git:
url: https://github.com/simolus3/moor.git
ref: beta
path: sqlparser
@simolus3 Thank you very much. This is such a relief. I confirmed that the problem is fixed. I ran it 5 times in a row and it was successful every time. I will definitely use the dependency overrides for now.
When do you anticipate to promote the fix to production?
Glad to hear that! I'll try to release a new version next weekend and I'll let you know when it's published.
I run several times:
flutter clean && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs
flutter packages pub run build_runner build --delete-conflicting-outputs
and now it works flawlessly! Nice job! : )
Sorry for the slow update - the version containing the fix has since been released to pub.
I had the same problem, what happened in my case was that my files were capitalized for example: "MyStoreBank.dart", what I did was change to the lower name "my_store_bank.dart" ... doing this the loop stopped and the .g file was created when I ran "flutter pub run build_runner build"
Most helpful comment
In moor 3.0, I've added the
eagerly_load_dart_astbuilder option, which should fix this problem.I still think this is something the build system should take care of. Other packages like
reflectableran into similar problems (https://github.com/dart-lang/build/issues/2634), but it looks like an equivalent of theeagerly_load_dart_astdidn't work for them.If you run into this problem, can you try enabling that option and let me know if that fixes it or not?