drift
drift copied to clipboard
Analyzer error with Moor vscode plugin
I am using moor files + the vscode analyzer plugin. I'm not sure how to reproduce the error, but it happens quite frequently.
Here is the log Moor 3.3.1
error NoSuchMethodError: The getter 'references' was called on null.
Receiver: null
Tried calling: references
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _visit (package:moor_generator/src/utils/entity_reference_sorter.dart:26:34)
#2 _visit (package:moor_generator/src/utils/entity_reference_sorter.dart:37:7)
#3 sortEntitiesTopologically (package:moor_generator/src/utils/entity_reference_sorter.dart:18:7)
#4 AnalyzeDartStep.analyze (package:moor_generator/src/analyzer/runner/steps/analyze_dart.dart:40:29)
#5 Task._analyze (package:moor_generator/src/analyzer/runner/task.dart:220:45)
#6 Task.runTask (package:moor_generator/src/analyzer/runner/task.dart:61:13)
<asynchronous suspension>
#7 MoorDriver.performWork (package:moor_generator/src/backends/common/driver.dart:107:18)
#8 AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:1967:24)
<asynchronous suspension>
#9 AnalysisDriverScheduler.start (package:analyzer/src/dart/analysis/driver.dart:1890:5)
#10 new ServerPlugin (package:analyzer_plugin/plugin/plugin.dart:74:29)
#11 new BaseMoorPlugin (package:moor_generator/src/backends/common/base_plugin.dart:16:47)
#12 new _MoorPlugin&BaseMoorPlugin&OutlineMixin (package:moor_generator/src/backends/plugin/plugin.dart)
#13 new _MoorPlugin&BaseMoorPlugin&OutlineMixin&FoldingMixin (package:moor_generator/src/backends/plugin/plugin.dart)
#14 new _MoorPlugin&BaseMoorPlugin&OutlineMixin&FoldingMixin&CompletionMixin (package:moor_generator/src/backends/plugin/plugin.dart)
#15 new _MoorPlugin&BaseMoorPlugin&OutlineMixin&FoldingMixin&CompletionMixin&NavigationMixin (package:moor_generator/src/backends/plugin/plugin.dart)
#16 new MoorPlugin (package:moor_generator/src/backends/plugin/plugin.dart:27:43)
#17 new MoorPlugin.forProduction (package:moor_generator/src/backends/plugin/plugin.dart:33:12)
#18 start (package:moor_generator/integrations/plugin.dart:7:34)
#19 main (file:///home/david/.dartServer/.plugin_manager/56a5218d35ad95701e42d0a28ec03e1d/analyzer_plugin/bin/plugin.dart:13:5)
#20 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:32)
#21 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
Apologies for the slow response here. This bug can have many causes, so it's difficult to track down.
We have an assert to avoid calling _visit with a null entity, it looks like the analysis server does not enable asserts for plugins though.
https://github.com/simolus3/moor/blob/5cbc331ddaf7a3031d98a905c2e05080d9fbb2c8/moor_generator/lib/src/utils/entity_reference_sorter.dart#L25-L27
However, it might be possible to reproduce this error through a build too. I assume the error happens somewhere with a syntactically incomplete moor file. So when you get that error, you could try to run the build manually via dart --enable-asserts .dart_tool/build/entrypoint/build.dart build --verbose and see if that triggers it too. That might help to find what's causing this.
Thanks @simolus3 ! I'll try next time I get the error on vscode. The strange thing is that the build_runner generates all the moor related files perfectly fine, so I wouldn't expect a syntax error on the moor files.