Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
cdfe3955
Unverified
Commit
cdfe3955
authored
Mar 18, 2021
by
Jonah Williams
Committed by
GitHub
Mar 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] handle OSError 2 from current working directory (#78380)
parent
e2bbdb97
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
5 deletions
+31
-5
error_handling_io.dart
packages/flutter_tools/lib/src/base/error_handling_io.dart
+16
-5
error_handling_io_test.dart
...tools/test/general.shard/base/error_handling_io_test.dart
+15
-0
No files found.
packages/flutter_tools/lib/src/base/error_handling_io.dart
View file @
cdfe3955
...
...
@@ -24,6 +24,10 @@ import 'platform.dart';
// ToolExit and a message that is more clear than the FileSystemException by
// itself.
/// On windows this is error code 2: ERROR_FILE_NOT_FOUND, and on
/// macOS/Linux it is error code 2/ENOENT: No such file or directory.
const
int
kSystemCannotFindFile
=
2
;
/// A [FileSystem] that throws a [ToolExit] on certain errors.
///
/// If a [FileSystem] error is not caused by the Flutter tool, and can only be
...
...
@@ -83,10 +87,6 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
// Certain error codes indicate the file could not be found. It could have
// been deleted by a different program while the tool was running.
// if it still exists, the file likely exists on a read-only volume.
//
// On windows this is error code 2: ERROR_FILE_NOT_FOUND, and on
// macOS/Linux it is error code 2/ENOENT: No such file or directory.
const
int
kSystemCannotFindFile
=
2
;
if
(
err
?.
osError
?.
errorCode
!=
kSystemCannotFindFile
||
_noExitOnFailure
)
{
rethrow
;
}
...
...
@@ -105,7 +105,18 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
@override
Directory
get
currentDirectory
{
return
_runSync
(()
=>
directory
(
delegate
.
currentDirectory
),
platform:
_platform
);
try
{
return
_runSync
(()
=>
directory
(
delegate
.
currentDirectory
),
platform:
_platform
);
}
on
FileSystemException
catch
(
err
)
{
// Special handling for OS error 2 for current directory only.
if
(
err
.
osError
.
errorCode
==
kSystemCannotFindFile
)
{
throwToolExit
(
'Unable to read current working directory. This can happen if the directory the '
'Flutter tool was run from was moved or deleted.'
);
}
rethrow
;
}
}
@override
...
...
packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart
View file @
cdfe3955
...
...
@@ -8,6 +8,7 @@ import 'dart:io' as io; // ignore: dart_io_import;
import
'package:file/file.dart'
;
import
'package:file/memory.dart'
;
import
'package:file_testing/file_testing.dart'
;
import
'package:flutter_tools/src/base/common.dart'
;
import
'package:flutter_tools/src/base/error_handling_io.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
...
...
@@ -370,6 +371,7 @@ void main() {
const
int
eperm
=
1
;
const
int
enospc
=
28
;
const
int
eacces
=
13
;
MockFileSystem
mockFileSystem
;
ErrorHandlingFileSystem
fs
;
...
...
@@ -475,6 +477,19 @@ void main() {
expect
(()
=>
directory
.
existsSync
(),
throwsToolExit
(
message:
expectedMessage
));
});
testWithoutContext
(
'When the current working directory disappears'
,
()
async
{
setupReadMocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
kSystemCannotFindFile
,
);
expect
(()
=>
fs
.
currentDirectory
,
throwsToolExit
(
message:
'Unable to read current working directory'
));
// Error is not caught by other operations.
expect
(()
=>
fs
.
file
(
'foo'
).
readAsStringSync
(),
throwsFileSystemException
(
kSystemCannotFindFile
));
});
});
group
(
'throws ToolExit on macOS'
,
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment