Skip to content

Commit e81bc5e

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Record unhandled exceptions in message handler zone
This `socketError` callback doesn't record exceptions to the instrumentation service because they were expected to be things like the socket closing. However it was also used for unhandled errors in the zone used for handling errors, which meant they also were not logged. This meant the user would see the error text, but the stack trace would never be logged anyway. With this change, unhandled exceptions from the zone will be logged through the instrumentation service too. Fixes #62082 Change-Id: I71d56a8b3c9241744eb614d74de46c190d61f2e3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464381 Commit-Queue: Keerti Parthasarathy <keertip@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Keerti Parthasarathy <keertip@google.com>
1 parent 3508315 commit e81bc5e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ class LspAnalysisServer extends AnalysisServer {
559559
logException(errorMessage, error, stackTrace);
560560
completer?.setComplete();
561561
}
562-
}, socketError);
562+
}, unhandledZoneError);
563563
}
564564

565565
/// Logs the error on the client using window/logMessage.
@@ -991,10 +991,22 @@ class LspAnalysisServer extends AnalysisServer {
991991
/// There was an error related to the socket from which messages are being
992992
/// read.
993993
void socketError(Object error, StackTrace? stackTrace) {
994-
// Don't send to instrumentation service; not an internal error.
994+
// Don't send to instrumentation service; not an internal error. Probably
995+
// caused by server shutdown or similar.
995996
sendServerErrorNotification('Socket error', error, stackTrace);
996997
}
997998

999+
/// There was an unhandled async error in the zone used to execute the
1000+
/// message handler.
1001+
void unhandledZoneError(Object error, StackTrace? stackTrace) {
1002+
// Record to the instrumentation log so the stack trace is accessible. This
1003+
// is an unhandled exception that was not awaited and is almost certainly a
1004+
// bug.
1005+
instrumentationService.logException(error, stackTrace);
1006+
1007+
sendServerErrorNotification('Unhandled handler error', error, stackTrace);
1008+
}
1009+
9981010
/// Updates the active set of workspace folders.
9991011
///
10001012
/// This is provided by the client at startup and may be updated by

0 commit comments

Comments
 (0)