Open MariosKoni opened 1 day ago
Summary: The user's Dart analyzer keeps terminating, preventing them from working. They've tried restarting the analyzer and removing Dart-related files from their user folder, but the issue persists. The analyzer logs show that it's receiving and processing requests, but then abruptly stops.
@DanTup
Found the solution, not a bug of the analyzer but a wrong import from me, most probably caused a recursive import and it overflowed the analyzer. I was importing a barrel file while declaring the file as a part.
(Edit: I posted this before I saw your reply.. see reply below)
@MariosKoni are you able to share any code/project that triggers this? This same error came up in https://github.com/dart-lang/sdk/issues/54099 when pasting TypeScript into a Dart file, but could not be reproduced.
The error suggests something may be wrong with an export
directive, but I haven't been able to trigger it with any kind of invalid code I could come up with. Could you review where you use export
and see if there's anything unusual that could be causing this? Thanks!
@MariosKoni do you know the code that triggered this? Even if your code is invalid, we should prevent the analysis server from terminating. Thanks!
So, firstly I was importing a barrel file from another package
import 'package:some_api/some_api.dart';
And after that, I was declaring
part '../src/use_cases/use_cases.dart';
(a barrel file exporting all use cases)
What I should have done (and did) was that, I should have declared each part (each use case) for my repository and forget about exporting. It was bad coding from my side.
@MariosKoni thank you, I was able to reproduce it like this:
lib/my_app.dart
part 'use_cases.dart';
lib/use_cases.dart
part of 'my_app.dart';
export
[2:50:25 PM] [Analyzer] [Info] <== Content-Length: 97
Content-Type: application/vscode-jsonrpc; charset=utf-8
[2:50:25 PM] [Analyzer] [Error] [Null check operator used on a null value
#0 MetadataResolver.visitExportDirective (package:analyzer/src/summary2/metadata_resolver.dart:108:17)
#1 ExportDirectiveImpl.accept (package:analyzer/src/dart/ast/ast.dart:5789:50)
#2 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:12583:20)
#3 MetadataResolver.visitCompilationUnit (package:analyzer/src/summary2/metadata_resolver.dart:68:21)
#4 CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:3607:50)
#5 LibraryBuilder.resolveMetadata (package:analyzer/src/summary2/library_builder.dart:733:24)
#6 Linker._resolveMetadata (package:analyzer/src/summary2/link.dart:457:15)
#7 Linker._buildOutlines (package:analyzer/src/summary2/link.dart:272:5)
I'll re-open this, because it's a bug that should be fixed.
@scheglov the fix might be as simple as changing the !
to ?
here:
But I'm not familiar with this code so I don't know if not being able to resetMetadataFlags()
might impact anything else.
My analyzer keeps getting terminated. It used to do that sometimes but it usually restarts itself and everything's fine. However, today, some hours into the shift, it started getting terminated and after five times it remained shut down. This means I can't continue my work properly. I tried this fix, seems the issue seemed the same but it didn't work. I have also tried removing everything related to dart in user folder, no luck there either. The log is the following:
My Flutter doctor is the following:
My vs code dart exception version is 3.98.1