Unverified Commit 19fbe98d authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[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.
parent 576d6b58
...@@ -330,6 +330,16 @@ class ErrorHandlingDirectory ...@@ -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 @override
String toString() => delegate.toString(); String toString() => delegate.toString();
} }
......
...@@ -93,6 +93,8 @@ void setupDirectoryMocks({ ...@@ -93,6 +93,8 @@ void setupDirectoryMocks({
.thenThrow(FileSystemException('', '', OSError('', errorCode))); .thenThrow(FileSystemException('', '', OSError('', errorCode)));
when(mockDirectory.deleteSync()) when(mockDirectory.deleteSync())
.thenThrow(FileSystemException('', '', OSError('', errorCode))); .thenThrow(FileSystemException('', '', OSError('', errorCode)));
when(mockDirectory.existsSync())
.thenThrow(FileSystemException('', '', OSError('', errorCode)));
} }
void main() { void main() {
...@@ -203,6 +205,20 @@ void main() { ...@@ -203,6 +205,20 @@ void main() {
expect(() => directory.createSync(recursive: true), expect(() => directory.createSync(recursive: true),
throwsToolExit(message: expectedMessage)); 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', () { group('throws ToolExit on Linux', () {
...@@ -298,6 +314,20 @@ void main() { ...@@ -298,6 +314,20 @@ void main() {
expect(() => directory.createTempSync('prefix'), expect(() => directory.createTempSync('prefix'),
throwsToolExit(message: expectedMessage)); 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', () { group('throws ToolExit on macOS', () {
...@@ -393,6 +423,20 @@ void main() { ...@@ -393,6 +423,20 @@ void main() {
expect(() => directory.createTempSync('prefix'), expect(() => directory.createTempSync('prefix'),
throwsToolExit(message: expectedMessage)); 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', () { testWithoutContext('Caches path context correctly', () {
......
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