Unverified Commit 738a7747 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] Handle disk device not found (#90996)

parent d94c18d2
...@@ -768,6 +768,7 @@ void _handleWindowsException(Exception e, String? message, int errorCode) { ...@@ -768,6 +768,7 @@ void _handleWindowsException(Exception e, String? message, int errorCode) {
const int kUserMappedSectionOpened = 1224; const int kUserMappedSectionOpened = 1224;
const int kAccessDenied = 5; const int kAccessDenied = 5;
const int kFatalDeviceHardwareError = 483; const int kFatalDeviceHardwareError = 483;
const int kDeviceDoesNotExist = 433;
// Catch errors and bail when: // Catch errors and bail when:
String? errorMessage; String? errorMessage;
...@@ -796,6 +797,12 @@ void _handleWindowsException(Exception e, String? message, int errorCode) { ...@@ -796,6 +797,12 @@ void _handleWindowsException(Exception e, String? message, int errorCode) {
'$message. There is a problem with the device driver ' '$message. There is a problem with the device driver '
'that this file or directory is stored on.'; 'that this file or directory is stored on.';
break; break;
case kDeviceDoesNotExist:
errorMessage =
'$message. The device was not found.'
'\n$e\n'
'Verify the device is mounted and try again.';
break;
default: default:
// Caller must rethrow the exception. // Caller must rethrow the exception.
break; break;
......
...@@ -100,6 +100,7 @@ void main() { ...@@ -100,6 +100,7 @@ void main() {
const int kUserMappedSectionOpened = 1224; const int kUserMappedSectionOpened = 1224;
const int kUserPermissionDenied = 5; const int kUserPermissionDenied = 5;
const int kFatalDeviceHardwareError = 483; const int kFatalDeviceHardwareError = 483;
const int kDeviceDoesNotExist = 433;
late FileExceptionHandler exceptionHandler; late FileExceptionHandler exceptionHandler;
...@@ -260,6 +261,44 @@ void main() { ...@@ -260,6 +261,44 @@ void main() {
throwsToolExit(message: expectedMessage)); 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(<int>[0]),
throwsToolExit(message: expectedMessage));
expect(() async => file.writeAsString(''),
throwsToolExit(message: expectedMessage));
expect(() => file.writeAsBytesSync(<int>[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 { testWithoutContext('when creating a temporary dir on a full device', () async {
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem( final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
delegate: MemoryFileSystem.test(opHandle: exceptionHandler.opHandle), delegate: MemoryFileSystem.test(opHandle: exceptionHandler.opHandle),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment