From abb48f495b5a4cd5cdd1f4e65d4041ff97cdf2e4 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 13 Jan 2021 14:25:37 -0800 Subject: [PATCH] [flutter_tools] add error handling wrapping for File.createSync (#73890) --- .../flutter_tools/lib/src/base/error_handling_io.dart | 11 +++++++++++ .../general.shard/base/error_handling_io_test.dart | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/packages/flutter_tools/lib/src/base/error_handling_io.dart b/packages/flutter_tools/lib/src/base/error_handling_io.dart index 1425926ccb2..f350511e1d0 100644 --- a/packages/flutter_tools/lib/src/base/error_handling_io.dart +++ b/packages/flutter_tools/lib/src/base/error_handling_io.dart @@ -263,6 +263,17 @@ class ErrorHandlingFile ); } + @override + void createSync({bool recursive = false}) { + _runSync( + () => delegate.createSync( + recursive: recursive, + ), + platform: _platform, + failureMessage: 'Flutter failed to create file at "${delegate.path}"', + ); + } + @override RandomAccessFile openSync({FileMode mode = FileMode.read}) { return _runSync( diff --git a/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart b/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart index 0157857c245..f68eadb7aa4 100644 --- a/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart +++ b/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart @@ -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 {