From 25dd8684b146ab877e260519f203c15be0d7bf41 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Fri, 8 Jan 2021 11:56:13 -0800 Subject: [PATCH] [flutter_tools] add 483 to non-recoverable errors (#73579) --- .../lib/src/base/error_handling_io.dart | 7 ++++++ .../base/error_handling_io_test.dart | 24 +++++++++++++++++++ 2 files changed, 31 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 eb3202951b..1425926ccb 100644 --- a/packages/flutter_tools/lib/src/base/error_handling_io.dart +++ b/packages/flutter_tools/lib/src/base/error_handling_io.dart @@ -692,6 +692,8 @@ void _handleWindowsException(Exception e, String message, int errorCode) { const int kDeviceFull = 112; const int kUserMappedSectionOpened = 1224; const int kAccessDenied = 5; + const int kFatalDeviceHardwareError = 483; + // Catch errors and bail when: String errorMessage; switch (errorCode) { @@ -714,6 +716,11 @@ void _handleWindowsException(Exception e, String message, int errorCode) { 'Do you have an antivirus program running? ' 'Try disabling your antivirus program and try again.'; break; + case kFatalDeviceHardwareError: + errorMessage = + '$message. There is a problem with the device driver ' + 'that this file or directory is stored on.'; + break; default: // Caller must rethrow the exception. break; 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 67615e4a7d..0157857c24 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 @@ -173,6 +173,7 @@ void main() { const int kDeviceFull = 112; const int kUserMappedSectionOpened = 1224; const int kUserPermissionDenied = 5; + const int kFatalDeviceHardwareError = 483; MockFileSystem mockFileSystem; ErrorHandlingFileSystem fs; @@ -271,6 +272,29 @@ void main() { throwsToolExit(message: expectedMessage)); }); + testWithoutContext('when the device driver has a fatal error', () async { + setupWriteMocks( + mockFileSystem: mockFileSystem, + fs: fs, + errorCode: kFatalDeviceHardwareError, + ); + + final File file = fs.file('file'); + + const String expectedMessage = 'There is a problem with the device driver ' + 'that this file or directory is stored on'; + expect(() async => await file.writeAsBytes([0]), + throwsToolExit(message: expectedMessage)); + expect(() async => await file.writeAsString(''), + throwsToolExit(message: expectedMessage)); + expect(() => file.writeAsBytesSync([0]), + throwsToolExit(message: expectedMessage)); + expect(() => file.writeAsStringSync(''), + throwsToolExit(message: expectedMessage)); + expect(() => file.openSync(), + throwsToolExit(message: expectedMessage)); + }); + testWithoutContext('when creating a temporary dir on a full device', () async { setupDirectoryMocks( mockFileSystem: mockFileSystem,