Repository navigation
Commit 0e1f50f
authored
[flutter_tools] Forward encoding in ErrorHandlingFile.readAsStringSync (flutter#196136)
Previously, `ErrorHandlingFile.readAsStringSync` dropped its `encoding`
parameter when calling `delegate.readAsStringSync()`, forcing UTF-8
decoding even when callers requested another encoding (unlike
`readAsString`, `readAsLines`, and `readAsLinesSync`, which already
forwarded `encoding`). Because `flutter_tools` wraps `LocalFileSystem`
in `ErrorHandlingFileSystem`, callers such as
`ScreenshotCommand.ensureOutputIsNotJsonRpcError` (which passes
`AsciiCodec(allowInvalid: true)` when checking small screenshot files
for JSON-RPC error payloads) crashed with a `FileSystemException`.
Forward `encoding` to `delegate.readAsStringSync(encoding: encoding)`
and add regression tests covering `ErrorHandlingFile.readAsStringSync`
backed by `LocalFileSystem` and
`ScreenshotCommand.ensureOutputIsNotJsonRpcError` on
`ErrorHandlingFileSystem`.
Fixes flutter#196225
Previous output:
```
Screenshot written to flutter_01.skp (0kB).
FileSystemException: Failed to decode data using encoding 'utf-8', path = '/tmp/repro_screenshot_skp.QPQNLT/flutter_01.skp'
#0 _File._tryDecode (dart:io/file_impl.dart:704:7)
#1 _File.readAsStringSync (dart:io/file_impl.dart:715:7)
#2 ForwardingFile.readAsStringSync (package:file/src/forwarding/forwarding_file.dart:99:16)
#3 ErrorHandlingFile.readAsStringSync.<anonymous closure> (package:flutter_tools/src/base/error_handling_io.dart:258:22)
#4 _runSync (package:flutter_tools/src/base/error_handling_io.dart:1116:16)
#5 ErrorHandlingFile.readAsStringSync (package:flutter_tools/src/base/error_handling_io.dart:257:12)
#6 ScreenshotCommand.ensureOutputIsNotJsonRpcError (package:flutter_tools/src/commands/screenshot.dart:198:39)
flutter#7 ScreenshotCommand.runSkia (package:flutter_tools/src/commands/screenshot.dart:180:5)
<asynchronous suspension>
flutter#8 ScreenshotCommand.runCommand (package:flutter_tools/src/commands/screenshot.dart:123:19)
<asynchronous suspension>
flutter#9 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:876:27)
<asynchronous suspension>
flutter#10 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
flutter#11 CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
flutter#12 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:689:9)
<asynchronous suspension>
flutter#13 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
flutter#14 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:619:5)
<asynchronous suspension>
flutter#15 FlutterCommandRunner.run (package:flutter_tools/src/runner/flutter_command_runner.dart:379:5)
<asynchronous suspension>
flutter#16 run.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:419: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 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
flutter#20 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:
```
Screenshot written to flutter_01.skp (0kB).
```1 parent 2229a60 commit 0e1f50f
3 files changed
Lines changed: 47 additions & 3 deletions
File tree
- packages/flutter_tools
- lib/src/base
- test
- commands.shard/hermetic
- general.shard/base
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | | - | |
| 258 | + | |
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
164 | 180 | | |
165 | 181 | | |
166 | 182 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
2169 | 2169 | | |
2170 | 2170 | | |
2171 | 2171 | | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
2172 | 2200 | | |
2173 | 2201 | | |
2174 | 2202 | | |
| |||
0 commit comments