Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InconsistentAnalysisException #452

Closed
apoleo88 opened this issue Mar 21, 2020 · 31 comments
Closed

InconsistentAnalysisException #452

apoleo88 opened this issue Mar 21, 2020 · 31 comments
Labels
bug Something isn't working generator Affects the generator

Comments

@apoleo88
Copy link

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

@simolus3 simolus3 added bug Something isn't working generator Affects the generator labels Mar 21, 2020
@simolus3
Copy link
Owner

Thanks for the report. I think this is some kind of bug in Dart's build system or the analyzer (see also dart-lang/build#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.

@apoleo88
Copy link
Author

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.

@apoleo88
Copy link
Author

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?

@inexcode
Copy link

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.

@yamsergey
Copy link

I've faced the same issue. Removing all generated classes and flutter clean did the job for me.

@brenoasm
Copy link

I had the same issue, and removing the mode: InsertModeOrReplace made the build to finish.

@ragnor-rs
Copy link

ragnor-rs commented Apr 23, 2020

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.

@simolus3
Copy link
Owner

simolus3 commented May 6, 2020

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 (dart-lang/build#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?

@simolus3 simolus3 closed this as completed May 6, 2020
@brenoasm
Copy link

brenoasm commented May 6, 2020

Tried to set the eagerly_load_dart_ast like this:

  $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.

@simolus3 simolus3 reopened this May 6, 2020
@majdi21
Copy link

majdi21 commented May 7, 2020

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).

@atreeon
Copy link

atreeon commented May 7, 2020

I'm getting a similar problem with a completely different library

dart-lang/build#2689

Have you tried renaming the files? For me, if these problems are the same...

  1. I get the error
  2. I rename the file the analysis is having a problem with
  3. rerun build & it works

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)

@apoleo88
Copy link
Author

apoleo88 commented May 10, 2020

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.

@yamsergey
Copy link

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

@brenoasm
Copy link

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.

@kuhnroyal
Copy link
Contributor

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.

@brenoasm
Copy link

Just some minutes later and I got the error again rs, so it continue to happens.

@Sofianel5
Copy link

Coming from a completely different code generation package that uses build_runner. Probably a flutter or build_runner problem.

@brenoasm
Copy link

@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...

@apoleo88
Copy link
Author

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.

@simolus3
Copy link
Owner

simolus3 commented Jun 2, 2020

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.

@atreeon
Copy link

atreeon commented Jun 4, 2020

@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

@atreeon
Copy link

atreeon commented Jun 4, 2020

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

@simolus3
Copy link
Owner

simolus3 commented Jun 4, 2020

@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.

@jesseframework
Copy link

Am having same proble

@majdi21
Copy link

majdi21 commented Jun 21, 2020

@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).

build_runner_out_err.txt

@simolus3
Copy link
Owner

simolus3 commented Jun 21, 2020

@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

@majdi21
Copy link

majdi21 commented Jun 21, 2020

@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?

@simolus3
Copy link
Owner

Glad to hear that! I'll try to release a new version next weekend and I'll let you know when it's published.

@apoleo88
Copy link
Author

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! : )

@simolus3
Copy link
Owner

Sorry for the slow update - the version containing the fix has since been released to pub.

@CabralPro
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working generator Affects the generator
Projects
None yet
Development

No branches or pull requests