Skip to content

Commit 38b6062

Browse files
srawlinsCommit Queue
authored andcommitted
DAS plugins: Test how an unsupported request is handled.
Change-Id: If214c32f396867a5af0a3bfcc40946121c895aef Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442285 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent a6acd34 commit 38b6062

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,15 @@ class PluginSession {
11271127
// If a RequestError is returned in the response, report this as an
11281128
// exception.
11291129
if (response.error case var error?) {
1130+
if (error.code == RequestErrorCode.UNKNOWN_REQUEST) {
1131+
// The plugin doesn't support this request. It may just be using an
1132+
// older version of the `analysis_server_plugin` package.
1133+
info.instrumentationService.logInfo(
1134+
"Plugin cannot handle request '${request.method}' with parameters: "
1135+
'$parameters.',
1136+
);
1137+
return;
1138+
}
11301139
var stackTrace = StackTrace.fromString(error.stackTrace!);
11311140
var exception = PluginException(error.message);
11321141
info.reportException(

pkg/analysis_server_plugin/test/src/plugin_server_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:analyzer/dart/ast/ast.dart';
1212
import 'package:analyzer_plugin/protocol/protocol_common.dart' as protocol;
1313
import 'package:analyzer_plugin/protocol/protocol_constants.dart' as protocol;
1414
import 'package:analyzer_plugin/protocol/protocol_generated.dart' as protocol;
15+
import 'package:analyzer_plugin/protocol/protocol_generated.dart';
1516
import 'package:analyzer_plugin/utilities/assist/assist.dart';
1617
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
1718
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
@@ -180,6 +181,20 @@ bool b = false;
180181
_expectAnalysisError(params.errors.single, message: 'No doubles message');
181182
}
182183

184+
Future<void> test_unsupportedRequest() async {
185+
writeAnalysisOptionsWithPlugin();
186+
newFile(filePath, 'bool b = false;');
187+
188+
await channel
189+
.sendRequest(protocol.AnalysisSetContextRootsParams([contextRoot]));
190+
191+
// This request is unsupported.
192+
var response = await channel.sendRequest(
193+
protocol.CompletionGetSuggestionsParams(filePath, 0 /* offset */));
194+
195+
expect(response.error?.code, RequestErrorCode.UNKNOWN_REQUEST);
196+
}
197+
183198
Future<void> test_updateContent_addOverlay() async {
184199
writeAnalysisOptionsWithPlugin();
185200
newFile(filePath, 'int b = 7;');

0 commit comments

Comments
 (0)