Skip to content

Commit fa8bf67

Browse files
author
Jonah Williams
authored
[flutter_tools] catch errors when getting cwd (flutter#74744)
1 parent 384b4d1 commit fa8bf67

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
102102
static bool _noExitOnFailure = false;
103103

104104
@override
105-
Directory get currentDirectory => directory(delegate.currentDirectory);
105+
Directory get currentDirectory {
106+
return _runSync(() => directory(delegate.currentDirectory), platform: _platform);
107+
}
106108

107109
@override
108110
File file(dynamic path) => ErrorHandlingFile(
@@ -710,7 +712,7 @@ void _handleWindowsException(Exception e, String message, int errorCode) {
710712
switch (errorCode) {
711713
case kAccessDenied:
712714
errorMessage =
713-
'$message. The flutter tool cannot access the file.\n'
715+
'$message. The flutter tool cannot access the file or directory.\n'
714716
'Please ensure that the SDK and/or project is installed in a location '
715717
'that has read/write permissions for the current user.';
716718
break;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ void setupReadMocks({
8787
}) {
8888
final MockFile mockFile = MockFile();
8989
when(mockFileSystem.file(any)).thenReturn(mockFile);
90+
when(mockFileSystem.currentDirectory).thenThrow(FileSystemException('', '', OSError('', errorCode)));
9091
when(mockFile.readAsStringSync(
9192
encoding: anyNamed('encoding'),
9293
)).thenThrow(FileSystemException('', '', OSError('', errorCode)));
@@ -345,7 +346,7 @@ void main() {
345346
throwsToolExit(message: expectedMessage));
346347
});
347348

348-
testWithoutContext('When reading from a file without permission', () {
349+
testWithoutContext('When reading from a file or directory without permission', () {
349350
setupReadMocks(
350351
mockFileSystem: mockFileSystem,
351352
fs: fs,
@@ -357,6 +358,8 @@ void main() {
357358
const String expectedMessage = 'Flutter failed to read a file at';
358359
expect(() => file.readAsStringSync(),
359360
throwsToolExit(message: expectedMessage));
361+
expect(() => fs.currentDirectory,
362+
throwsToolExit(message: 'The flutter tool cannot access the file or directory'));
360363
});
361364
});
362365

@@ -579,7 +582,7 @@ void main() {
579582
throwsToolExit(message: expectedMessage));
580583
});
581584

582-
testWithoutContext('When reading from a file without permission', () {
585+
testWithoutContext('When reading from a file or directory without permission', () {
583586
setupReadMocks(
584587
mockFileSystem: mockFileSystem,
585588
fs: fs,
@@ -591,6 +594,8 @@ void main() {
591594
const String expectedMessage = 'Flutter failed to read a file at';
592595
expect(() => file.readAsStringSync(),
593596
throwsToolExit(message: expectedMessage));
597+
expect(() => fs.currentDirectory,
598+
throwsToolExit(message: 'The flutter tool cannot access the file or directory'));
594599
});
595600
});
596601

0 commit comments

Comments
 (0)