Skip to content

Commit 86b62a3

Browse files
authored
Tiny fix about outdated message (#114391)
1 parent a41c447 commit 86b62a3

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:meta/meta.dart';
56
import 'package:vm_service/vm_service.dart' as vm_service;
67

78
import '../base/common.dart';
@@ -168,7 +169,7 @@ class ScreenshotCommand extends FlutterCommand {
168169
sink.add(base64.decode(skp.json?['skp'] as String));
169170
await sink.close();
170171
_showOutputFileInfo(outputFile);
171-
_ensureOutputIsNotJsonRpcError(outputFile);
172+
ensureOutputIsNotJsonRpcError(outputFile);
172173
return true;
173174
}
174175

@@ -192,7 +193,7 @@ class ScreenshotCommand extends FlutterCommand {
192193
sink.add(base64.decode(response.json?['screenshot'] as String));
193194
await sink.close();
194195
_showOutputFileInfo(outputFile);
195-
_ensureOutputIsNotJsonRpcError(outputFile);
196+
ensureOutputIsNotJsonRpcError(outputFile);
196197
return true;
197198
}
198199

@@ -205,15 +206,16 @@ class ScreenshotCommand extends FlutterCommand {
205206
}
206207
}
207208

208-
void _ensureOutputIsNotJsonRpcError(File outputFile) {
209+
@visibleForTesting
210+
static void ensureOutputIsNotJsonRpcError(File outputFile) {
209211
if (outputFile.lengthSync() >= 1000) {
210212
return;
211213
}
212214
final String content = outputFile.readAsStringSync(
213215
encoding: const AsciiCodec(allowInvalid: true),
214216
);
215217
if (content.startsWith('{"jsonrpc":"2.0", "error"')) {
216-
throwToolExit('It appears the output file contains an error message, not valid skia output.');
218+
throwToolExit('It appears the output file contains an error message, not valid output.');
217219
}
218220
}
219221

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

+20
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,24 @@ void main() {
106106
message: 'File was not created, ensure path is valid'));
107107
});
108108
});
109+
110+
group('Screenshot output validation', () {
111+
testWithoutContext('successful', () async {
112+
final MemoryFileSystem fs = MemoryFileSystem.test();
113+
fs.file('test.png').createSync();
114+
115+
expect(() => ScreenshotCommand.ensureOutputIsNotJsonRpcError(fs.file('test.png')),
116+
returnsNormally);
117+
});
118+
119+
testWithoutContext('failed', () async {
120+
final MemoryFileSystem fs = MemoryFileSystem.test();
121+
fs.file('test.png').writeAsStringSync('{"jsonrpc":"2.0", "error":"something"}');
122+
123+
expect(
124+
() => ScreenshotCommand.ensureOutputIsNotJsonRpcError(fs.file('test.png')),
125+
throwsToolExit(
126+
message: 'It appears the output file contains an error message, not valid output.'));
127+
});
128+
});
109129
}

0 commit comments

Comments
 (0)