Skip to content

[flutter_tools] Handle target VM filesystem errors in DevFS.create - #196234

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
bkonyi:issue-196118
Nov 17, 2026
Merged

auto-submit[bot] merged 7 commits into
flutter:masterfrom
bkonyi:issue-196118

Conversation

@bkonyi

@bkonyi bkonyi commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Previously, DevFS.create only translated VM service disconnection RPC errors (kServiceDisappeared, kConnectionDisposed) and retried 1001 (kFileSystemAlreadyExists), rethrowing all other RPCError instances as unhandled tool crashes. When the target Dart VM failed to create a temporary directory during _createDevFS (for example due to a read-only, inaccessible, or full TMP/TEMP/TMPDIR directory on the target machine or device), the VM service returned RPCError -32603 (kInternalError) wrapping a dart:io FileSystemException (PathAccessException, PathNotFoundException, PathExistsException, or FileSystemException). That unhandled RPCError escaped HotRunner._attach / HotRunner.run and triggered crash reporting.

Translate -32603 RPCError responses whose details wrap a target VM FileSystemException into DevFSException('Failed to create DevFS on device', fileSystemError) in DevFS.create (including on the retry attempt after destroy()), keeping DevFSException.message PII-free for GitHubTemplateCreator.sanitizedCrashException while surfacing the underlying OS filesystem error in DevFSException.error and DevFSException.toString(). Non-filesystem -32603 internal VM errors continue to rethrow to crash reporting. Also type DevFSException.error as Object? and omit null optional fields in DevFSException.toString().

Reproduced against flutter_tester launched with a read-only TMPDIR=/tmp/flutter_devfs_repro_readonly (chmod 0555) and BOT=true on flutter attach:

Previous output:

_createDevFS: (-32603) Internal error
_createDevFS: Unexpected exception:PathAccessException: Creation of temporary directory failed, path = '/tmp/flutter_devfs_repro_readonly' (OS Error: Permission denied, errno = 13)
#0      _checkForErrorResponse (dart:io/common.dart:58:9)
#1      _Directory.createTemp.<anonymous closure> (dart:io/directory_impl.dart:163:7)
<asynchronous suspension>
#2      createTempDirCallback (dart:vmservice_io:101:16)
<asynchronous suspension>
#3      DevFS._createDevFS (dart:_vmservice/devfs.dart:197:21)
<asynchronous suspension>
#4      VMService._routeRequestImpl (dart:_vmservice:759:16)
<asynchronous suspension>
#5      VMService.routeRequest (dart:_vmservice:726:22)
<asynchronous suspension>
#6      WebSocketClient.post (dart:vmservice_io/vmservice_server.dart:64:3)
<asynchronous suspension>

#0      new _OutstandingRequest (package:vm_service/src/vm_service.dart:280:34)
#1      VmService._call.<anonymous closure> (package:vm_service/src/vm_service.dart:1962:25)
#2      VmService._call (package:vm_service/src/vm_service.dart:1974:8)
#3      VmService.callServiceExtension (package:vm_service/src/vm_service.dart:1913:14)
#4      FlutterVmService.createDevFS (package:flutter_tools/src/vmservice.dart:1060:20)
#5      DevFS.create (package:flutter_tools/src/devfs.dart:497:61)
#6      FlutterDevice.setupDevFS (package:flutter_tools/src/resident_runner.dart:331:19)
#7      HotRunner._initDevFS (package:flutter_tools/src/run_hot.dart:473:23)
#8      HotRunner._attach (package:flutter_tools/src/run_hot.dart:280:41)
<asynchronous suspension>
#9      AttachCommand._attach (package:flutter_tools/src/commands/attach.dart:296:24)
<asynchronous suspension>
#10     AttachCommand.runCommand (package:flutter_tools/src/commands/attach.dart:250:7)
<asynchronous suspension>
#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:876:27)
<asynchronous suspension>
#12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
#13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#14     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:689:9)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
#16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:619:5)
<asynchronous suspension>
#17     FlutterCommandRunner.run (package:flutter_tools/src/runner/flutter_command_runner.dart:379:5)
<asynchronous suspension>
#18     run.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:419:19)
<asynchronous suspension>
#19     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
#20     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
#21     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
#22     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:

Error initializing DevFS: DevFSException(Failed to create DevFS on device, PathAccessException: Creation of temporary directory failed, path = '/tmp/flutter_devfs_repro_readonly' (OS Error: Permission denied, errno = 13))

Fixes #196118

Previously, `DevFS.create` only translated VM service disconnection RPC errors (`kServiceDisappeared`, `kConnectionDisposed`) and retried `1001` (`kFileSystemAlreadyExists`), rethrowing all other `RPCError` instances as unhandled tool crashes. When the target Dart VM failed to create a temporary directory during `_createDevFS` (for example due to a read-only, inaccessible, or full `TMP`/`TEMP`/`TMPDIR` directory on the target machine or device), the VM service returned `RPCError` `-32603` (`kInternalError`) wrapping a `dart:io` `FileSystemException` (`PathAccessException`, `PathNotFoundException`, `PathExistsException`, or `FileSystemException`). That unhandled `RPCError` escaped `HotRunner._attach` / `HotRunner.run` and triggered crash reporting.

Translate `-32603` `RPCError` responses whose `details` wrap a target VM `FileSystemException` into `DevFSException('Failed to create DevFS on device', fileSystemError)` in `DevFS._createDevFSOnDevice` (including on the retry attempt after `destroy()`), keeping `DevFSException.message` PII-free for `GitHubTemplateCreator.sanitizedCrashException` while surfacing the underlying OS filesystem error in `DevFSException.error` and `DevFSException.toString()`. Non-filesystem `-32603` internal VM errors continue to rethrow to crash reporting. Also type `DevFSException.error` as `Object?` and omit `null` optional fields in `DevFSException.toString()`.

Reproduced against `flutter_tester` launched with a read-only `TMPDIR=/tmp/flutter_devfs_repro_readonly` (`chmod 0555`) and `BOT=true` on `flutter attach`:

Previous output:
```
_createDevFS: (-32603) Internal error
_createDevFS: Unexpected exception:PathAccessException: Creation of temporary directory failed, path = '/tmp/flutter_devfs_repro_readonly' (OS Error: Permission denied, errno = 13)
#0      _checkForErrorResponse (dart:io/common.dart:58:9)
#1      _Directory.createTemp.<anonymous closure> (dart:io/directory_impl.dart:163:7)
<asynchronous suspension>
#2      createTempDirCallback (dart:vmservice_io:101:16)
<asynchronous suspension>
#3      DevFS._createDevFS (dart:_vmservice/devfs.dart:197:21)
<asynchronous suspension>
#4      VMService._routeRequestImpl (dart:_vmservice:759:16)
<asynchronous suspension>
#5      VMService.routeRequest (dart:_vmservice:726:22)
<asynchronous suspension>
#6      WebSocketClient.post (dart:vmservice_io/vmservice_server.dart:64:3)
<asynchronous suspension>

#0      new _OutstandingRequest (package:vm_service/src/vm_service.dart:280:34)
#1      VmService._call.<anonymous closure> (package:vm_service/src/vm_service.dart:1962:25)
#2      VmService._call (package:vm_service/src/vm_service.dart:1974:8)
#3      VmService.callServiceExtension (package:vm_service/src/vm_service.dart:1913:14)
#4      FlutterVmService.createDevFS (package:flutter_tools/src/vmservice.dart:1060:20)
#5      DevFS.create (package:flutter_tools/src/devfs.dart:497:61)
#6      FlutterDevice.setupDevFS (package:flutter_tools/src/resident_runner.dart:331:19)
flutter#7      HotRunner._initDevFS (package:flutter_tools/src/run_hot.dart:473:23)
flutter#8      HotRunner._attach (package:flutter_tools/src/run_hot.dart:280:41)
<asynchronous suspension>
flutter#9      AttachCommand._attach (package:flutter_tools/src/commands/attach.dart:296:24)
<asynchronous suspension>
flutter#10     AttachCommand.runCommand (package:flutter_tools/src/commands/attach.dart:250:7)
<asynchronous suspension>
flutter#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:876:27)
<asynchronous suspension>
flutter#12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
flutter#13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
flutter#14     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:689:9)
<asynchronous suspension>
flutter#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
flutter#16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:619:5)
<asynchronous suspension>
flutter#17     FlutterCommandRunner.run (package:flutter_tools/src/runner/flutter_command_runner.dart:379:5)
<asynchronous suspension>
flutter#18     run.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:419:19)
<asynchronous suspension>
flutter#19     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
flutter#20     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
flutter#21     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:174:19)
<asynchronous suspension>
flutter#22     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:
```
Error initializing DevFS: DevFSException(Failed to create DevFS on device, PathAccessException: Creation of temporary directory failed, path = '/tmp/flutter_devfs_repro_readonly' (OS Error: Permission denied, errno = 13))
```

Fixes flutter#196118
@bkonyi bkonyi added CICD Run CI/CD t: cp-candidate A PR that should be considered for a cherry-pick upon landing. labels Nov 9, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Nov 9, 2026
@bkonyi
bkonyi marked this pull request as ready for review November 12, 2026 02:44

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors DevFS creation to extract and include target VM file system error details when throwing a DevFSException, and adds corresponding unit and integration tests. The review feedback points out that the ?error syntax used in DevFSException.toString() is non-standard Dart and suggests using Dart 3 pattern matching instead. Additionally, it is recommended to make the stack trace extraction in _extractTargetFileSystemError more robust against Windows line endings.

Addresses review feedback on flutter#196234 by defining `_stackTraceStartPattern = RegExp(r'\r?\n#0')` in `DevFS._extractTargetFileSystemError` and updating the Windows `PathAccessException` unit test in `devfs_test.dart` to cover `\r\n#0` stack trace delimiters.

Current output:
```
Error initializing DevFS: DevFSException(Failed to create DevFS on device, PathAccessException: Creation of temporary directory failed, path = '/tmp/flutter_devfs_repro_readonly' (OS Error: Permission denied, errno = 13))
```
Inline the existing-filesystem retry loop and target VM filesystem `RPCError` translation directly in `DevFS.create`, removing `_createDevFSOnDevice`, `_extractTargetFileSystemError`, and redundant regex helpers.

Add optional `data` support to `FakeRPCError` in `test/src/fake_vm_services.dart`, replace the custom `_RpcErrorWithDetailsHost` harness in `devfs_test.dart` with `FakeVmServiceHost`, and drop the redundant multi-process `flutter_attach_test.dart` integration test.
Replace the conditionless `for` loop in `DevFS.create` with an idiomatic `do-while` loop keyed on `baseUri == null`, removing both `break` and the `_baseUri!` null assertion.
Drop `dotAll: true` from `DevFS._targetFileSystemErrorPattern` so `.*`
stops at the newline before the target VM stack trace, removing the
manual `details.split('\n#0')` and `error.replaceAll` steps. Document
both the `_createDevFS` `kInternalError` wire format and the static
`DevFSException.message` crash-sanitization contract.
@bkonyi
bkonyi requested a review from chingjun November 13, 2026 18:33
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 2026
@auto-submit

auto-submit Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196234, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label.

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 17, 2026
Merged via the queue into flutter:master with commit 95d9833 Nov 17, 2026
22 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 2026
@bkonyi bkonyi added the cp: stable cherry pick this pull request to stable release candidate branch label Nov 18, 2026
LouiseHsu pushed a commit to flutter/packages that referenced this pull request Nov 18, 2026
flutter/flutter@2f09f96...06f32f8

2026-11-18 [email protected] Move macOS
desktop builds to ThinLTO (flutter/flutter#196804)
2026-11-18 [email protected] Roll Dart SDK from
5ed55b4b2ebc to 753488ede427 (2 revisions) (flutter/flutter#196893)
2026-11-18 [email protected] Roll Packages from
9af69be to dca2e58 (7 revisions) (flutter/flutter#196892)
2026-11-18 [email protected] Roll Skia from 503a380ebecc
to 81ee7327e81c (29 revisions) (flutter/flutter#196889)
2026-11-18 [email protected] Roll Dart SDK from
26e38955d9d4 to 5ed55b4b2ebc (4 revisions) (flutter/flutter#196843)
2026-11-18 [email protected] Fix permissions for action updates
(flutter/flutter#196791)
2026-11-18 [email protected] iOS: Apply platform view mutators from
FlutterPlatformViewLayer (flutter/flutter#196753)
2026-11-18 [email protected] [flutter_tools] Remove ambient Doctor,
FeatureFlags, and device getters (flutter/flutter#196572)
2026-11-18 [email protected] Fix
RelativeRect.lerp crash when b is null (flutter/flutter#196655)
2026-11-18 [email protected] [web] Harden
WebP and GIF header readers against truncated and malformed buffers
(flutter/flutter#196075)
2026-11-17 [email protected] Enable apps to
control focus behavior during app lifecycle changes via
`FocusLifecyclePolicy` (flutter/flutter#190570)
2026-11-17 [email protected] Don't re-run the code freeze check
on label changes (flutter/flutter#196745)
2026-11-17 [email protected] Android: Report
FlutterView as a text editor while a text input client is attached
(flutter/flutter#193074)
2026-11-17 [email protected] Roll Packages from
4c6a7d3 to 9af69be (5 revisions) (flutter/flutter#196812)
2026-11-17 [email protected] [flutter_tools] Handle target VM filesystem
errors in DevFS.create (flutter/flutter#196234)
2026-11-17 [email protected] [flutter_tools] Clarify analytics reporting
status when on a feature branch (flutter/flutter#194496)
2026-11-17 [email protected] [web] Recover
CanvasKit surfaces from WebGL failures without per-frame null crashes
(flutter/flutter#196257)
2026-11-17 [email protected] [devicelab] Trigger navigation tap via
Flutter Driver in service_extensions_test (flutter/flutter#194456)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to
ensure that a human
is aware of the problem.

To file a bug in Packages:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit Bot pushed a commit that referenced this pull request Nov 18, 2026
…create (#196895)

Cherry-pick of #196234.

This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

### Issue Link:
#196118

### Impact Description:
This issue impacts local development (`flutter run` and `flutter attach`), not shipped production apps. When the target Dart VM cannot create a temporary DevFS directory (for example, due to restricted `TEMP` permissions on Windows or full disk space on a simulator or desktop host), the VM service returns `RPCError` `-32603`. `DevFS.create` rethrows that error unhandled and triggers a `P1` top-crasher report in `flutter_tools` instead of reporting the underlying OS filesystem failure.

### Changelog Description:
[flutter/196118] When the target device or host temporary directory is inaccessible or full during debug launch (most commonly on Windows and iOS Simulator), flutter run and flutter attach crash with an unhandled RPCError.

### Workaround:
Ensure the temporary directory used by the target device or host (`%TEMP%` / `%LOCALAPPDATA%\Temp` on Windows, or `TMPDIR` on macOS, Linux, and simulators) exists, is writable by the current user, and has free disk space.

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
1. Run `flutter test test/general.shard/devfs_test.dart` in `packages/flutter_tools` and verify all tests pass, including target VM filesystem `RPCError` translation on initial `create()` and retry after `destroy()`, plus rethrowing non-filesystem `-32603` errors.
2. Create a read-only temporary directory (`mkdir /tmp/readonly_tmp && chmod 0555 /tmp/readonly_tmp`), launch `flutter_tester` with `TMPDIR=/tmp/readonly_tmp`, and run `BOT=true flutter attach --debug-uri=<vm-service-uri>`. Verify `flutter attach` exits with `Error initializing DevFS: DevFSException(Failed to create DevFS on device, PathAccessException: ...)` instead of an unhandled `RPCError` crash report.
jose-pr pushed a commit to Boriken-Dev/flutter that referenced this pull request Nov 23, 2026
…create (#196895)

Cherry-pick of flutter/flutter#196234.

This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

### Issue Link:
flutter/flutter#196118

### Impact Description:
This issue impacts local development (`flutter run` and `flutter attach`), not shipped production apps. When the target Dart VM cannot create a temporary DevFS directory (for example, due to restricted `TEMP` permissions on Windows or full disk space on a simulator or desktop host), the VM service returns `RPCError` `-32603`. `DevFS.create` rethrows that error unhandled and triggers a `P1` top-crasher report in `flutter_tools` instead of reporting the underlying OS filesystem failure.

### Changelog Description:
[flutter/196118] When the target device or host temporary directory is inaccessible or full during debug launch (most commonly on Windows and iOS Simulator), flutter run and flutter attach crash with an unhandled RPCError.

### Workaround:
Ensure the temporary directory used by the target device or host (`%TEMP%` / `%LOCALAPPDATA%\Temp` on Windows, or `TMPDIR` on macOS, Linux, and simulators) exists, is writable by the current user, and has free disk space.

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
1. Run `flutter test test/general.shard/devfs_test.dart` in `packages/flutter_tools` and verify all tests pass, including target VM filesystem `RPCError` translation on initial `create()` and retry after `destroy()`, plus rethrowing non-filesystem `-32603` errors.
2. Create a read-only temporary directory (`mkdir /tmp/readonly_tmp && chmod 0555 /tmp/readonly_tmp`), launch `flutter_tester` with `TMPDIR=/tmp/readonly_tmp`, and run `BOT=true flutter attach --debug-uri=<vm-service-uri>`. Verify `flutter attach` exits with `Error initializing DevFS: DevFSException(Failed to create DevFS on device, PathAccessException: ...)` instead of an unhandled `RPCError` crash report.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD cp: stable cherry pick this pull request to stable release candidate branch t: cp-candidate A PR that should be considered for a cherry-pick upon landing. tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tool_crash] Unhandled RPCError (-32603) in DevFS.create when target VM fails to create temporary directory

2 participants