Skip to content

Commit 19fbe98

Browse files
[flutter_tools] pass existsSync through error handling io (flutter#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.
1 parent 576d6b5 commit 19fbe98

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

packages/flutter_tools/lib/src/base/error_handling_io.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ class ErrorHandlingDirectory
330330
);
331331
}
332332

333+
@override
334+
bool existsSync() {
335+
return _runSync<bool>(
336+
() => delegate.existsSync(),
337+
platform: _platform,
338+
failureMessage:
339+
'Flutter failed to check for directory existence at "${delegate.path}"',
340+
);
341+
}
342+
333343
@override
334344
String toString() => delegate.toString();
335345
}

packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ void setupDirectoryMocks({
9393
.thenThrow(FileSystemException('', '', OSError('', errorCode)));
9494
when(mockDirectory.deleteSync())
9595
.thenThrow(FileSystemException('', '', OSError('', errorCode)));
96+
when(mockDirectory.existsSync())
97+
.thenThrow(FileSystemException('', '', OSError('', errorCode)));
9698
}
9799

98100
void main() {
@@ -203,6 +205,20 @@ void main() {
203205
expect(() => directory.createSync(recursive: true),
204206
throwsToolExit(message: expectedMessage));
205207
});
208+
209+
testWithoutContext('when checking for directory existence with permission issues', () async {
210+
setupDirectoryMocks(
211+
mockFileSystem: mockFileSystem,
212+
fs: fs,
213+
errorCode: kUserPermissionDenied,
214+
);
215+
216+
final Directory directory = fs.directory('directory');
217+
218+
const String expectedMessage = 'Flutter failed to check for directory existence at';
219+
expect(() => directory.existsSync(),
220+
throwsToolExit(message: expectedMessage));
221+
});
206222
});
207223

208224
group('throws ToolExit on Linux', () {
@@ -298,6 +314,20 @@ void main() {
298314
expect(() => directory.createTempSync('prefix'),
299315
throwsToolExit(message: expectedMessage));
300316
});
317+
318+
testWithoutContext('when checking for directory existence with permission issues', () async {
319+
setupDirectoryMocks(
320+
mockFileSystem: mockFileSystem,
321+
fs: fs,
322+
errorCode: eacces,
323+
);
324+
325+
final Directory directory = fs.directory('directory');
326+
327+
const String expectedMessage = 'Flutter failed to check for directory existence at';
328+
expect(() => directory.existsSync(),
329+
throwsToolExit(message: expectedMessage));
330+
});
301331
});
302332

303333
group('throws ToolExit on macOS', () {
@@ -393,6 +423,20 @@ void main() {
393423
expect(() => directory.createTempSync('prefix'),
394424
throwsToolExit(message: expectedMessage));
395425
});
426+
427+
testWithoutContext('when checking for directory existence with permission issues', () async {
428+
setupDirectoryMocks(
429+
mockFileSystem: mockFileSystem,
430+
fs: fs,
431+
errorCode: eacces,
432+
);
433+
434+
final Directory directory = fs.directory('directory');
435+
436+
const String expectedMessage = 'Flutter failed to check for directory existence at';
437+
expect(() => directory.existsSync(),
438+
throwsToolExit(message: expectedMessage));
439+
});
396440
});
397441

398442
testWithoutContext('Caches path context correctly', () {

0 commit comments

Comments
 (0)