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
eadd30eb
Unverified
Commit
eadd30eb
authored
May 08, 2020
by
Shi-Hao Hong
Committed by
GitHub
May 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve arb FormatException error message (#56373)
parent
26dc70dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
27 deletions
+41
-27
gen_l10n_types.dart
dev/tools/localization/gen_l10n_types.dart
+9
-1
gen_l10n_test.dart
dev/tools/test/localization/gen_l10n_test.dart
+32
-26
No files found.
dev/tools/localization/gen_l10n_types.dart
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$'
);
...
...
dev/tools/test/localization/gen_l10n_test.dart
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
=
'''
...
...
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