Skip to content

Commit 37d80ce

Browse files
authored
add filesystem error handling to systemTempDirectory (#158481)
Fixes flutter/flutter#153777. To summarize that issue, `ErrorHandlingFileSystem.systemTempDirectory` calls [`LocalFileSystem.systemTempDirectory`](https://github.com/flutter/flutter/blob/45c8881eb289e3b68e890cefa0acd13dbf800147/packages/flutter_tools/lib/src/base/file_system.dart#L229), which makes a `Directory.createSync` call, which can throw exceptions that _should_ be handled and result in a graceful tool exit (e.g. insufficient storage). However, we aren't catching those, hence this issue. All we need to do is wrap that call with the `FileSystemException`-handling logic we already have in the tool. See the diff. I don't think I'll be cherry-picking this since 1) it's not an extremely common crash and 2) users can probably pick apart the crash message and figure out that they need to clear some storage space to proceed. <details> <summary> Pre-launch checklist </summary> </details>
1 parent 9a2e249 commit 37d80ce

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

packages/flutter_tools/lib/src/base/error_handling_io.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
124124

125125
@override
126126
Directory get systemTempDirectory {
127-
return directory(delegate.systemTempDirectory);
127+
return _runSync(() => directory(delegate.systemTempDirectory), platform: _platform);
128128
}
129129

130130
@override

packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ void main() {
884884
});
885885
});
886886

887-
testWithoutContext("ErrorHandlingFileSystem.systemTempDirectory wraps delegates filesystem's systemTempDirectory", () {
887+
testWithoutContext("ErrorHandlingFileSystem.systemTempDirectory wraps delegate filesystem's systemTempDirectory", () {
888888
final FileExceptionHandler exceptionHandler = FileExceptionHandler();
889889

890890
final MemoryFileSystem delegate = MemoryFileSystem.test(
@@ -921,6 +921,35 @@ Please ensure that the SDK and/or project is installed in a location that has re
921921
);
922922
});
923923

924+
testWithoutContext("ErrorHandlingFileSystem.systemTempDirectory handles any exception thrown by the delegate's systemTempDirectory implementation", () {
925+
final FileExceptionHandler exceptionHandler = FileExceptionHandler();
926+
exceptionHandler.addTempError(
927+
FileSystemOp.create,
928+
const FileSystemException(
929+
'Creation of temporary directory failed',
930+
'some/temp/path',
931+
OSError(
932+
'No space left on device',
933+
28,
934+
),
935+
),
936+
);
937+
938+
final MemoryFileSystem delegate = MemoryFileSystem.test(
939+
opHandle: exceptionHandler.opHandle,
940+
);
941+
942+
final FileSystem fs = ErrorHandlingFileSystem(
943+
delegate: delegate,
944+
platform: FakePlatform(),
945+
);
946+
947+
expect(
948+
() => fs.systemTempDirectory,
949+
throwsToolExit(message: 'Free up space and try again.'),
950+
);
951+
});
952+
924953
group('ProcessManager on windows throws tool exit', () {
925954
const int kDeviceFull = 112;
926955
const int kUserMappedSectionOpened = 1224;

0 commit comments

Comments
 (0)