[flutter_tools] Handle disk device not found (#90996)
This commit is contained in:
committed by
GitHub
parent
d94c18d2b9
commit
738a7747cc
@@ -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;
|
||||
|
||||
@@ -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(<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 {
|
||||
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
|
||||
delegate: MemoryFileSystem.test(opHandle: exceptionHandler.opHandle),
|
||||
|
||||
Reference in New Issue
Block a user