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 5ad6f59edb..3678e45fe2 100644 --- a/packages/flutter_tools/lib/src/base/error_handling_io.dart +++ b/packages/flutter_tools/lib/src/base/error_handling_io.dart @@ -768,6 +768,7 @@ void _handleWindowsException(Exception e, String? message, int errorCode) { const int kUserMappedSectionOpened = 1224; const int kAccessDenied = 5; const int kFatalDeviceHardwareError = 483; + const int kDeviceDoesNotExist = 433; // Catch errors and bail when: String? errorMessage; @@ -796,6 +797,12 @@ void _handleWindowsException(Exception e, String? message, int errorCode) { '$message. There is a problem with the device driver ' 'that this file or directory is stored on.'; break; + case kDeviceDoesNotExist: + errorMessage = + '$message. The device was not found.' + '\n$e\n' + 'Verify the device is mounted and try again.'; + 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 84c515f3c1..5bb7f923e7 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 @@ -100,6 +100,7 @@ void main() { const int kUserMappedSectionOpened = 1224; const int kUserPermissionDenied = 5; const int kFatalDeviceHardwareError = 483; + const int kDeviceDoesNotExist = 433; late FileExceptionHandler exceptionHandler; @@ -260,6 +261,44 @@ void main() { throwsToolExit(message: expectedMessage)); }); + testWithoutContext('when the device does not exist', () async { + final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem( + delegate: MemoryFileSystem.test(opHandle: exceptionHandler.opHandle), + platform: windowsPlatform, + ); + final File file = fileSystem.file('file'); + + exceptionHandler.addError( + file, + FileSystemOp.write, + FileSystemException('', file.path, const OSError('', kDeviceDoesNotExist)), + ); + exceptionHandler.addError( + file, + FileSystemOp.open, + FileSystemException('', file.path, const OSError('', kDeviceDoesNotExist)), + ); + exceptionHandler.addError( + file, + FileSystemOp.create, + FileSystemException('', file.path, const OSError('', kDeviceDoesNotExist)), + ); + + const String expectedMessage = 'The device was not found.'; + expect(() async => file.writeAsBytes([0]), + throwsToolExit(message: expectedMessage)); + expect(() async => file.writeAsString(''), + throwsToolExit(message: expectedMessage)); + expect(() => file.writeAsBytesSync([0]), + throwsToolExit(message: expectedMessage)); + expect(() => file.writeAsStringSync(''), + 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 { final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem( delegate: MemoryFileSystem.test(opHandle: exceptionHandler.opHandle),