From 76bc462520ba462f7bfe810db0f2f1a288f68e97 Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Wed, 7 Apr 2021 13:19:04 -0700 Subject: [PATCH] migrate empty exceptions to tool exit with error message (#79898) --- .../flutter_tools/lib/src/localizations/gen_l10n.dart | 7 +++---- .../build_system/targets/localizations_test.dart | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart index aeaec77a54..267ac2b91a 100644 --- a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart +++ b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart @@ -6,6 +6,7 @@ import 'package:meta/meta.dart'; +import '../base/common.dart'; import '../base/file_system.dart'; import '../base/logger.dart'; import '../convert.dart'; @@ -32,7 +33,7 @@ void generateLocalizations({ logger: logger, ); if (options.useSyntheticPackage && !flutterManifest.generateSyntheticPackage) { - logger.printError( + throwToolExit( 'Attempted to generate localizations code without having ' 'the flutter: generate flag turned on.' '\n' @@ -40,7 +41,6 @@ void generateLocalizations({ 'been added and rebuild the project. Otherwise, the localizations ' 'source code will not be importable.' ); - throw Exception(); } precacheLanguageAndRegionTags(); @@ -71,8 +71,7 @@ void generateLocalizations({ ..loadResources() ..writeOutputFiles(logger, isFromYaml: true); } on L10nException catch (e) { - logger.printError(e.message); - throw Exception(); + throwToolExit(e.message); } } diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart index 810201f863..dc8b3de1d7 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart @@ -115,11 +115,10 @@ flutter: projectDir: fileSystem.currentDirectory, dependenciesDir: fileSystem.currentDirectory, ), - throwsA(isA()), - ); - expect( - logger.errorText, - contains('Attempted to generate localizations code without having the flutter: generate flag turned on.'), + throwsToolExit( + message: 'Attempted to generate localizations code without having the ' + 'flutter: generate flag turned on.', + ), ); });