add filesystem error handling to systemTempDirectory
(#158481)
Fixes https://github.com/flutter/flutter/issues/153777.
To summarize that issue, `ErrorHandlingFileSystem.systemTempDirectory` calls [`LocalFileSystem.systemTempDirectory`](45c8881eb2/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>
This commit is contained in:
parent
9a2e249025
commit
37d80ce25f
@ -124,7 +124,7 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
|
||||
|
||||
@override
|
||||
Directory get systemTempDirectory {
|
||||
return directory(delegate.systemTempDirectory);
|
||||
return _runSync(() => directory(delegate.systemTempDirectory), platform: _platform);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -884,7 +884,7 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
testWithoutContext("ErrorHandlingFileSystem.systemTempDirectory wraps delegates filesystem's systemTempDirectory", () {
|
||||
testWithoutContext("ErrorHandlingFileSystem.systemTempDirectory wraps delegate filesystem's systemTempDirectory", () {
|
||||
final FileExceptionHandler exceptionHandler = FileExceptionHandler();
|
||||
|
||||
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
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext("ErrorHandlingFileSystem.systemTempDirectory handles any exception thrown by the delegate's systemTempDirectory implementation", () {
|
||||
final FileExceptionHandler exceptionHandler = FileExceptionHandler();
|
||||
exceptionHandler.addTempError(
|
||||
FileSystemOp.create,
|
||||
const FileSystemException(
|
||||
'Creation of temporary directory failed',
|
||||
'some/temp/path',
|
||||
OSError(
|
||||
'No space left on device',
|
||||
28,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final MemoryFileSystem delegate = MemoryFileSystem.test(
|
||||
opHandle: exceptionHandler.opHandle,
|
||||
);
|
||||
|
||||
final FileSystem fs = ErrorHandlingFileSystem(
|
||||
delegate: delegate,
|
||||
platform: FakePlatform(),
|
||||
);
|
||||
|
||||
expect(
|
||||
() => fs.systemTempDirectory,
|
||||
throwsToolExit(message: 'Free up space and try again.'),
|
||||
);
|
||||
});
|
||||
|
||||
group('ProcessManager on windows throws tool exit', () {
|
||||
const int kDeviceFull = 112;
|
||||
const int kUserMappedSectionOpened = 1224;
|
||||
|
Loading…
x
Reference in New Issue
Block a user