Unverified Commit 38843814 authored by Tae Hyung Kim's avatar Tae Hyung Kim Committed by GitHub

Make gen-l10n error handling independent of logger state (#119644)

* init

* lint

* lint again
parent 8f90e2a7
......@@ -579,6 +579,10 @@ class LocalizationsGenerator {
// Whether we want to use escaping for ICU messages.
bool useEscaping = false;
/// Whether any errors were caught. This is set after encountering any errors
/// from calling [_generateMethod].
bool hadErrors = false;
/// The list of all arb path strings in [inputDirectory].
List<String> get arbPathStrings {
return _allBundles.bundles.map((AppResourceBundle bundle) => bundle.file.path).toList();
......@@ -1238,6 +1242,7 @@ The plural cases must be one of "=0", "=1", "=2", "zero", "one", "two", "few", "
.replaceAll('@(none)\n', '');
} on L10nParserException catch (error) {
logger.printError(error.toString());
hadErrors = true;
return '';
}
}
......@@ -1247,7 +1252,7 @@ The plural cases must be one of "=0", "=1", "=2", "zero", "one", "two", "few", "
final String generatedLocalizationsFile = _generateCode();
// If there were any syntax errors, don't write to files.
if (logger.hadErrorOutput) {
if (hadErrors) {
throw L10nException('Found syntax errors.');
}
......
......@@ -785,6 +785,28 @@ void main() {
});
group('generateLocalizations', () {
// Regression test for https://github.com/flutter/flutter/issues/119593
testWithoutContext('other logs from flutter_tools does not affect gen-l10n', () async {
_standardFlutterDirectoryL10nSetup(fs);
final Logger logger = BufferLogger.test();
logger.printError('An error output from a different tool in flutter_tools');
// Should run without error.
generateLocalizations(
fileSystem: fs,
options: LocalizationOptions(
arbDirectory: Uri.directory(defaultL10nPathString),
outputDirectory: Uri.directory(defaultL10nPathString, windows: false),
templateArbFile: Uri.file(defaultTemplateArbFileName, windows: false),
useSyntheticPackage: false,
),
logger: logger,
projectDir: fs.currentDirectory,
dependenciesDir: fs.currentDirectory,
);
});
testWithoutContext('forwards arguments correctly', () async {
_standardFlutterDirectoryL10nSetup(fs);
final LocalizationOptions options = LocalizationOptions(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment