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
d4f0c082
Unverified
Commit
d4f0c082
authored
Jan 13, 2021
by
Jonah Williams
Committed by
GitHub
Jan 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] do not crash if target file cannot be read for language version (#73879)
parent
7ec0e398
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
1 deletion
+31
-1
language_version.dart
packages/flutter_tools/lib/src/dart/language_version.dart
+11
-1
language_version_test.dart
..._tools/test/general.shard/dart/language_version_test.dart
+20
-0
No files found.
packages/flutter_tools/lib/src/dart/language_version.dart
View file @
d4f0c082
...
...
@@ -24,7 +24,17 @@ final LanguageVersion nullSafeVersion = LanguageVersion(2, 12);
/// https://github.com/dart-lang/language/blob/master/accepted/future-releases/language-versioning/feature-specification.md#individual-library-language-version-override
LanguageVersion
determineLanguageVersion
(
File
file
,
Package
package
)
{
int
blockCommentDepth
=
0
;
for
(
final
String
line
in
file
.
readAsLinesSync
())
{
// If reading the file fails, default to a null-safe version. The
// command will likely fail later in the process with a better error
// message.
List
<
String
>
lines
;
try
{
lines
=
file
.
readAsLinesSync
();
}
on
FileSystemException
{
return
nullSafeVersion
;
}
for
(
final
String
line
in
lines
)
{
final
String
trimmedLine
=
line
.
trim
();
if
(
trimmedLine
.
isEmpty
)
{
continue
;
...
...
packages/flutter_tools/test/general.shard/dart/language_version_test.dart
View file @
d4f0c082
...
...
@@ -4,8 +4,10 @@
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/convert.dart'
;
import
'package:flutter_tools/src/dart/language_version.dart'
;
import
'package:package_config/package_config.dart'
;
import
'package:test/fake.dart'
;
import
'../../src/common.dart'
;
...
...
@@ -249,4 +251,22 @@ library funstuff;
expect
(
determineLanguageVersion
(
file
,
package
),
LanguageVersion
(
2
,
7
));
});
testWithoutContext
(
'Returns null safe error if reading the file throws a FileSystemException'
,
()
{
final
Package
package
=
Package
(
'foo'
,
Uri
.
parse
(
'file://foo/'
),
languageVersion:
LanguageVersion
(
2
,
7
),
);
expect
(
determineLanguageVersion
(
FakeFile
(),
package
),
nullSafeVersion
);
});
}
class
FakeFile
extends
Fake
implements
File
{
@override
List
<
String
>
readAsLinesSync
({
Encoding
encoding
=
utf8ForTesting
})
{
throw
const
FileSystemException
();
}
}
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