Skip to content

Commit 215858f

Browse files
authored
[flutter_tools] Handle RPCError in ScreenshotCommand.runSkia (flutter#196132)
Previously, running `flutter screenshot --type=skia` against an application with Impeller enabled crashed with an unhandled `vm_service.RPCError` (`-32000`) because the engine rejects `_flutter.screenshotSkp` requests under Impeller and `ScreenshotCommand.runSkia` did not catch `RPCError`. Catch `vm_service.RPCError` in `ScreenshotCommand.runSkia` and exit cleanly via `throwToolExit` with the engine's error message. Previous output: ``` _flutter.screenshotSkp: (-32000) Cannot capture SKP screenshot with Impeller enabled. #0 new _OutstandingRequest (package:vm_service/src/vm_service.dart:280:34) flutter#1 VmService._call.<anonymous closure> (package:vm_service/src/vm_service.dart:1962:25) flutter#2 VmService._call (package:vm_service/src/vm_service.dart:1974:8) flutter#3 VmService.callServiceExtension (package:vm_service/src/vm_service.dart:1905:14) flutter#4 FlutterVmService._checkedCallServiceExtension (package:flutter_tools/src/vmservice.dart:835:28) flutter#5 FlutterVmService.screenshotSkp (package:flutter_tools/src/vmservice.dart:1069:12) flutter#6 ScreenshotCommand.runSkia (package:flutter_tools/src/commands/screenshot.dart:167:54) <asynchronous suspension> flutter#7 ScreenshotCommand.runCommand (package:flutter_tools/src/commands/screenshot.dart:123:19) <asynchronous suspension> flutter#8 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:876:27) <asynchronous suspension> flutter#9 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19) <asynchronous suspension> flutter#10 CommandRunner.runCommand (package:args/command_runner.dart:212:13) <asynchronous suspension> flutter#11 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:689:9) <asynchronous suspension> flutter#12 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19) <asynchronous suspension> flutter#13 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:619:5) <asynchronous suspension> flutter#14 FlutterCommandRunner.run (package:flutter_tools/src/runner/flutter_command_runner.dart:379:5) <asynchronous suspension> flutter#15 run.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:419:19) <asynchronous suspension> flutter#16 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19) <asynchronous suspension> flutter#17 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19) <asynchronous suspension> flutter#18 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19) <asynchronous suspension> flutter#19 main (package:flutter_tools/executable.dart:133:3) <asynchronous suspension> Feature flags enabled: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration, enable-riscv64, enable-hcpp ``` Current output: ``` The Skia picture request failed: Cannot capture SKP screenshot with Impeller enabled. ``` Fixes flutter#196119
1 parent bd40044 commit 215858f

4 files changed

Lines changed: 356 additions & 3 deletions

File tree

‎dev/bots/tool_test_durations.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
"test/integration.shard/observatory_port_test.dart": 24,
172172
"test/integration.shard/overall_experience_test.dart": 36,
173173
"test/integration.shard/plist_parser_test.dart": 0,
174+
"test/integration.shard/screenshot_test.dart": 15,
174175
"test/integration.shard/shader_compiler_test.dart": 3,
175176
"test/integration.shard/stateless_stateful_hot_reload_test.dart": 9,
176177
"test/integration.shard/swift_package_manager_add2app_test.dart": 0,
@@ -388,6 +389,7 @@
388389
"test/integration.shard/observatory_port_test.dart": 21,
389390
"test/integration.shard/overall_experience_test.dart": 30,
390391
"test/integration.shard/plist_parser_test.dart": 0,
392+
"test/integration.shard/screenshot_test.dart": 15,
391393
"test/integration.shard/shader_compiler_test.dart": 2,
392394
"test/integration.shard/stateless_stateful_hot_reload_test.dart": 7,
393395
"test/integration.shard/swift_package_manager_add2app_test.dart": 492,
@@ -605,6 +607,7 @@
605607
"test/integration.shard/observatory_port_test.dart": 44,
606608
"test/integration.shard/overall_experience_test.dart": 37,
607609
"test/integration.shard/plist_parser_test.dart": 0,
610+
"test/integration.shard/screenshot_test.dart": 15,
608611
"test/integration.shard/shader_compiler_test.dart": 3,
609612
"test/integration.shard/stateless_stateful_hot_reload_test.dart": 15,
610613
"test/integration.shard/swift_package_manager_add2app_test.dart": 0,

‎packages/flutter_tools/lib/src/commands/screenshot.dart‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ class ScreenshotCommand extends FlutterCommand {
164164
flutterVersion: flutterVersion,
165165
logger: logger,
166166
);
167-
final vm_service.Response? skp = await vmService.screenshotSkp();
167+
final vm_service.Response? skp;
168+
try {
169+
skp = await vmService.screenshotSkp();
170+
} on vm_service.RPCError catch (error) {
171+
throwToolExit('The Skia picture request failed: ${error.message}');
172+
}
168173
if (skp == null) {
169174
logger.printError(
170175
'The Skia picture request failed, probably because the device was '

‎packages/flutter_tools/test/commands.shard/hermetic/screenshot_command_test.dart‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,54 @@ Device 2 (mobile) • 456 • android • 1.2.3
312312
contains('The Skia picture request failed, probably because the device was disconnected'),
313313
);
314314
});
315+
316+
testWithoutContext('throws ToolExit when screenshotSkp fails with RPCError', () async {
317+
final fs = MemoryFileSystem.test();
318+
final logger = BufferLogger.test();
319+
final toolContext = FakeToolContext(fs: fs, logger: logger);
320+
321+
final fakeVmService = _FakeFlutterVmService(
322+
rpcError: vm_service.RPCError(
323+
kScreenshotSkpMethod,
324+
vm_service.RPCErrorKind.kServerError.code,
325+
'Cannot capture SKP screenshot with Impeller enabled.',
326+
),
327+
);
328+
329+
final command = ScreenshotCommand(
330+
toolContext: toolContext,
331+
vmServiceConnector:
332+
(
333+
Uri uri, {
334+
ReloadSources? reloadSources,
335+
Restart? restart,
336+
CompileExpression? compileExpression,
337+
FlutterProject? flutterProject,
338+
FlutterVersion? flutterVersion,
339+
PrintStructuredErrorLogMethod? printStructuredErrorLogMethod,
340+
CompressionOptions compression = CompressionOptions.compressionDefault,
341+
Device? device,
342+
required Logger logger,
343+
}) async {
344+
return fakeVmService;
345+
},
346+
);
347+
348+
await expectLater(
349+
() => createTestCommandRunner(command).run(<String>[
350+
'screenshot',
351+
'--type=skia',
352+
'--vm-service-url=http://localhost:8181',
353+
'--out=screenshot.skp',
354+
]),
355+
throwsToolExit(
356+
message:
357+
'The Skia picture request failed: '
358+
'Cannot capture SKP screenshot with Impeller enabled.',
359+
),
360+
);
361+
expect(fs.file('screenshot.skp').existsSync(), isFalse);
362+
});
315363
});
316364
}
317365

@@ -382,10 +430,16 @@ class _TestDeviceManager extends DeviceManager {
382430
}
383431

384432
class _FakeFlutterVmService extends Fake implements FlutterVmService {
385-
_FakeFlutterVmService({this.response});
433+
_FakeFlutterVmService({this.response, this.rpcError});
386434

387435
final vm_service.Response? response;
436+
final vm_service.RPCError? rpcError;
388437

389438
@override
390-
Future<vm_service.Response?> screenshotSkp() async => response;
439+
Future<vm_service.Response?> screenshotSkp() async {
440+
if (rpcError case final error?) {
441+
throw error;
442+
}
443+
return response;
444+
}
391445
}

0 commit comments

Comments
 (0)