mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[flutter_tools] pass existsSync through error handling io (#66704)
Crash reporting shows at least one instance of EACCES during an existsSync cache call. Add this to the list of error handling io methods. Did not add the async exists method since we lint against its usage.
This commit is contained in:
parent
576d6b582b
commit
19fbe98df3
@ -330,6 +330,16 @@ class ErrorHandlingDirectory
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool existsSync() {
|
||||
return _runSync<bool>(
|
||||
() => delegate.existsSync(),
|
||||
platform: _platform,
|
||||
failureMessage:
|
||||
'Flutter failed to check for directory existence at "${delegate.path}"',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => delegate.toString();
|
||||
}
|
||||
|
||||
@ -93,6 +93,8 @@ void setupDirectoryMocks({
|
||||
.thenThrow(FileSystemException('', '', OSError('', errorCode)));
|
||||
when(mockDirectory.deleteSync())
|
||||
.thenThrow(FileSystemException('', '', OSError('', errorCode)));
|
||||
when(mockDirectory.existsSync())
|
||||
.thenThrow(FileSystemException('', '', OSError('', errorCode)));
|
||||
}
|
||||
|
||||
void main() {
|
||||
@ -203,6 +205,20 @@ void main() {
|
||||
expect(() => directory.createSync(recursive: true),
|
||||
throwsToolExit(message: expectedMessage));
|
||||
});
|
||||
|
||||
testWithoutContext('when checking for directory existence with permission issues', () async {
|
||||
setupDirectoryMocks(
|
||||
mockFileSystem: mockFileSystem,
|
||||
fs: fs,
|
||||
errorCode: kUserPermissionDenied,
|
||||
);
|
||||
|
||||
final Directory directory = fs.directory('directory');
|
||||
|
||||
const String expectedMessage = 'Flutter failed to check for directory existence at';
|
||||
expect(() => directory.existsSync(),
|
||||
throwsToolExit(message: expectedMessage));
|
||||
});
|
||||
});
|
||||
|
||||
group('throws ToolExit on Linux', () {
|
||||
@ -298,6 +314,20 @@ void main() {
|
||||
expect(() => directory.createTempSync('prefix'),
|
||||
throwsToolExit(message: expectedMessage));
|
||||
});
|
||||
|
||||
testWithoutContext('when checking for directory existence with permission issues', () async {
|
||||
setupDirectoryMocks(
|
||||
mockFileSystem: mockFileSystem,
|
||||
fs: fs,
|
||||
errorCode: eacces,
|
||||
);
|
||||
|
||||
final Directory directory = fs.directory('directory');
|
||||
|
||||
const String expectedMessage = 'Flutter failed to check for directory existence at';
|
||||
expect(() => directory.existsSync(),
|
||||
throwsToolExit(message: expectedMessage));
|
||||
});
|
||||
});
|
||||
|
||||
group('throws ToolExit on macOS', () {
|
||||
@ -393,6 +423,20 @@ void main() {
|
||||
expect(() => directory.createTempSync('prefix'),
|
||||
throwsToolExit(message: expectedMessage));
|
||||
});
|
||||
|
||||
testWithoutContext('when checking for directory existence with permission issues', () async {
|
||||
setupDirectoryMocks(
|
||||
mockFileSystem: mockFileSystem,
|
||||
fs: fs,
|
||||
errorCode: eacces,
|
||||
);
|
||||
|
||||
final Directory directory = fs.directory('directory');
|
||||
|
||||
const String expectedMessage = 'Flutter failed to check for directory existence at';
|
||||
expect(() => directory.existsSync(),
|
||||
throwsToolExit(message: expectedMessage));
|
||||
});
|
||||
});
|
||||
|
||||
testWithoutContext('Caches path context correctly', () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user