Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flutter
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
ExcellentOSS
flutter
Commits
eadd30eb
Unverified
Commit
eadd30eb
authored
5 years ago
by
Shi-Hao Hong
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve arb FormatException error message (#56373)
parent
26dc70dc
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dev/tools/localization/gen_l10n_types.dart
+9
-1
9 additions, 1 deletion
dev/tools/localization/gen_l10n_types.dart
dev/tools/test/localization/gen_l10n_test.dart
+32
-26
32 additions, 26 deletions
dev/tools/test/localization/gen_l10n_test.dart
with
41 additions
and
27 deletions
dev/tools/localization/gen_l10n_types.dart
+
9
−
1
View file @
eadd30eb
...
...
@@ -363,8 +363,16 @@ class AppResourceBundle {
factory
AppResourceBundle
(
File
file
)
{
assert
(
file
!=
null
);
// Assuming that the caller has verified that the file exists and is readable.
Map
<
String
,
dynamic
>
resources
;
try
{
resources
=
json
.
decode
(
file
.
readAsStringSync
())
as
Map
<
String
,
dynamic
>;
}
on
FormatException
catch
(
e
)
{
throw
L10nException
(
'The arb file
${file.path}
has the following formatting issue:
\n
'
'
${e.toString()}
'
,
);
}
final
Map
<
String
,
dynamic
>
resources
=
json
.
decode
(
file
.
readAsStringSync
())
as
Map
<
String
,
dynamic
>;
String
localeString
=
resources
[
'@@locale'
]
as
String
;
if
(
localeString
==
null
)
{
final
RegExp
filenameRE
=
RegExp
(
r'^[^_]*_(\w+)\.arb$'
);
...
...
This diff is collapsed.
Click to expand it.
dev/tools/test/localization/gen_l10n_test.dart
+
32
−
26
View file @
eadd30eb
...
...
@@ -1284,40 +1284,46 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
});
});
test
(
'should throw when failing to parse the arb file'
,
()
{
const
String
arbFileWithTrailingComma
=
'''
test
(
'should throw with descriptive error message when failing to parse the '
'arb file'
,
()
{
const
String
arbFileWithTrailingComma
=
'''
{
"title": "Stocks",
"@title": {
"description": "Title for the Stocks application"
},
}'''
;
final
Directory
l10nDirectory
=
fs
.
currentDirectory
.
childDirectory
(
'lib'
)
.
childDirectory
(
'l10n'
)
.
.
createSync
(
recursive:
true
);
l10nDirectory
.
childFile
(
defaultTemplateArbFileName
)
.
writeAsStringSync
(
arbFileWithTrailingComma
);
final
Directory
l10nDirectory
=
fs
.
currentDirectory
.
childDirectory
(
'lib'
)
.
childDirectory
(
'l10n'
)
.
.
createSync
(
recursive:
true
);
l10nDirectory
.
childFile
(
defaultTemplateArbFileName
)
.
writeAsStringSync
(
arbFileWithTrailingComma
);
final
LocalizationsGenerator
generator
=
LocalizationsGenerator
(
fs
);
try
{
generator
.
initialize
(
inputPathString:
defaultL10nPathString
,
outputPathString:
defaultL10nPathString
,
templateArbFileName:
defaultTemplateArbFileName
,
outputFileString:
defaultOutputFileString
,
classNameString:
defaultClassNameString
,
);
generator
.
loadResources
();
generator
.
writeOutputFiles
();
}
on
FormatException
catch
(
e
)
{
expect
(
e
.
message
,
contains
(
'Unexpected character'
));
return
;
}
final
LocalizationsGenerator
generator
=
LocalizationsGenerator
(
fs
);
try
{
generator
.
initialize
(
inputPathString:
defaultL10nPathString
,
outputPathString:
defaultL10nPathString
,
templateArbFileName:
defaultTemplateArbFileName
,
outputFileString:
defaultOutputFileString
,
classNameString:
defaultClassNameString
,
);
generator
.
loadResources
();
generator
.
writeOutputFiles
();
}
on
L10nException
catch
(
e
)
{
expect
(
e
.
message
,
contains
(
'app_en.arb'
));
expect
(
e
.
message
,
contains
(
'FormatException'
));
expect
(
e
.
message
,
contains
(
'Unexpected character'
));
return
;
}
fail
(
'should fail with a FormatException due to a trailing comma in the '
'arb file.'
);
});
fail
(
'should fail with an L10nException due to a trailing comma in the '
'arb file.'
);
},
);
test
(
'should throw when resource is missing resource attribute'
,
()
{
const
String
arbFileWithMissingResourceAttribute
=
'''
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment