Skip to content

Poor user experience when an analyzer crash occurs as part of IDE integration #61068

@stereotype441

Description

@stereotype441

I've just discovered #61066, which I'll be sending out a fix for as soon as it passes trybots.

The bug was initially quite difficult to track down, and so I'm filing this issue in the hopes that we can improve the customer experience of an analyzer crash.

The issue started when I added a new field to the GeneratedErrorCodeFile class (in pkg/analyzer/tool/messages/error_code_info.dart), and attempted to add a named constructor parameter to assign it a default value:

@@ -728,8 +728,13 @@ class GeneratedErrorCodeFile {
   /// file they should import.
   final String preferredImportUri;
 
+  /// Whether the generated file should use the `const` keyword when generating
+  /// constructor invocations.
+  final bool shouldUseExplicitConst;
+
   const GeneratedErrorCodeFile({
     required this.path,
     required this.preferredImportUri,
+    {this.shouldUseExplicitConst = false}
   });
 }

As you can see, this code is incorrect. The existing parameters this.path and this.preferredImportUri are named, and so I should not have nested the new named parameter in {}.

Unbeknownst to me, this caused an exception to be thrown from deep inside the analyzer. But this exception was caught inside the analysis server, and no indication was given to me as a user that an exception had occurred. As a result, the effect of this mistake from my perspective was that the analyzer simply appeared to start behaving erratically. Errors and warnings stopped updating for the error_code_info.dart file. Clicking on the GeneratedErrorCodeFile constructor and selecting "Find usages" resulted in no usages. At no time was there any suggestion in my IDE (VSCode) that the analyzer had crashed. I even looked at the analyzer diagnostics page under the "Exceptions" tab, and no exceptions were shown.

The only clue I got that there had been an analyzer crash was that when I restarted the analysis server, VSCode helpfully popped up a dialog allowing me to examine the server log, and in the server log I found this line:

{"id":19,"jsonrpc":"2.0","error":{"code":-32013,"data":"/home/paulberry/dart1/sdk/pkg/analyzer/tool/messages/error_code_info.dart","message":"Analysis failed for file"}}Content-Length: 93

It was only when I saw this line that I thought to try analyzing the file error_code_info.dart using the command-line analyzer; when I did that, it reported a stacktrace, and I was finally able to track down the problem.

When an exception occurs that prevents the analysis server from being able to analyze a file, an indication should be given to the user that the file could not be analyzed. For example, perhaps an error message could be shown at the first line of the file. It should be possible for the user to navigate from this indication to a stack trace so that they can file a bug report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions