Skip to content

Commit 641ec4c

Browse files
srawlinsCommit Queue
authored andcommitted
DAS: report exceptions caught in plugin isolate as plugin exceptions
This change means that during `dart analyze`, an exception caught in a plugin isolate will be printed to the terminal, and the process will exit (similar to the support for when the isolate has static errors). Change-Id: I31b1ebe7a71a331274d4f1dc1ea1b94f33e2329b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415981 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent d5f1395 commit 641ec4c

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

pkg/analysis_server/lib/src/plugin/plugin_manager.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,17 @@ class PluginSession {
10571057
completer,
10581058
);
10591059
channel.sendRequest(request);
1060+
completer.future.then((response) {
1061+
// If a RequestError is returned in the response, report this as an
1062+
// exception.
1063+
if (response.error case var error?) {
1064+
var stackTrace = StackTrace.fromString(error.stackTrace!);
1065+
var exception = PluginException(error.message);
1066+
info.reportException(
1067+
CaughtException.withMessage(error.message, exception, stackTrace),
1068+
);
1069+
}
1070+
});
10601071
return completer.future;
10611072
}
10621073

pkg/analysis_server/test/src/plugin/plugin_manager_test.dart

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,7 @@ class DiscoveredPluginInfoTest with ResourceProviderMixin, _ContextRoot {
171171

172172
Future<void> test_start_running() async {
173173
plugin.currentSession = PluginSession(plugin);
174-
try {
175-
await plugin.start('', '');
176-
fail('Expected a StateError');
177-
} on StateError {
178-
// Expected.
179-
}
174+
expect(() => plugin.start('', ''), throwsStateError);
180175
}
181176

182177
void test_stop_notRunning() {
@@ -764,6 +759,32 @@ class PluginSessionTest with ResourceProviderMixin {
764759
expect(result, same(response));
765760
}
766761

762+
Future<void> test_handleResponse_withError() async {
763+
TestServerCommunicationChannel(session);
764+
var response = Response(
765+
'0' /* id */,
766+
1 /* requestTime */,
767+
error: RequestError(
768+
RequestErrorCode.PLUGIN_ERROR,
769+
'exception',
770+
stackTrace: 'some stackTrace',
771+
),
772+
);
773+
774+
var responseFuture = session.sendRequest(
775+
PluginVersionCheckParams('', '', ''),
776+
);
777+
session.handleResponse(response);
778+
await responseFuture;
779+
expect(
780+
notificationManager.pluginErrors,
781+
equals([
782+
'An error occurred while executing an analyzer plugin: exception\n'
783+
'some stackTrace',
784+
]),
785+
);
786+
}
787+
767788
void test_nextRequestId() {
768789
expect(session.requestId, 0);
769790
expect(session.nextRequestId, '0');
@@ -794,12 +815,7 @@ class PluginSessionTest with ResourceProviderMixin {
794815

795816
Future<void> test_start_running() async {
796817
TestServerCommunicationChannel(session);
797-
try {
798-
await session.start('', '');
799-
fail('Expected a StateError to be thrown');
800-
} on StateError {
801-
// Expected behavior
802-
}
818+
expect(() => session.start('', ''), throwsStateError);
803819
}
804820

805821
void test_stop_notRunning() {

0 commit comments

Comments
 (0)