[flutter_tools] add error handling wrapping for File.createSync (#73890)

This commit is contained in:
Jonah Williams 2021-01-13 14:25:37 -08:00 committed by GitHub
parent 1eb0bb52e1
commit abb48f495b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -263,6 +263,17 @@ class ErrorHandlingFile
);
}
@override
void createSync({bool recursive = false}) {
_runSync<void>(
() => delegate.createSync(
recursive: recursive,
),
platform: _platform,
failureMessage: 'Flutter failed to create file at "${delegate.path}"',
);
}
@override
RandomAccessFile openSync({FileMode mode = FileMode.read}) {
return _runSync<RandomAccessFile>(

View File

@ -76,6 +76,8 @@ void setupWriteMocks({
when(mockFile.openSync(
mode: anyNamed('mode'),
)).thenThrow(FileSystemException('', '', OSError('', errorCode)));
when(mockFile.createSync(recursive: anyNamed('recursive')))
.thenThrow(FileSystemException('', '', OSError('', errorCode)));
}
void setupReadMocks({
@ -230,6 +232,8 @@ void main() {
throwsToolExit(message: expectedMessage));
expect(() => file.openSync(),
throwsToolExit(message: expectedMessage));
expect(() => file.createSync(),
throwsToolExit(message: expectedMessage));
});
testWithoutContext('when writing to a full device', () async {
@ -293,6 +297,8 @@ void main() {
throwsToolExit(message: expectedMessage));
expect(() => file.openSync(),
throwsToolExit(message: expectedMessage));
expect(() => file.createSync(),
throwsToolExit(message: expectedMessage));
});
testWithoutContext('when creating a temporary dir on a full device', () async {
@ -390,6 +396,8 @@ void main() {
throwsToolExit(message: expectedMessage));
expect(() => file.openSync(),
throwsToolExit(message: expectedMessage));
expect(() => file.createSync(),
throwsToolExit(message: expectedMessage));
});
testWithoutContext('when access is denied for directories', () async {