From 23a82085be80a60dab9e35b92339bf3fcdc2cc47 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 23 Jan 2024 11:54:16 -0500 Subject: [PATCH] fix test --- lib/src/configuration.dart | 10 ++-------- .../utils/config-reader/config_reader.dart | 5 +++-- .../config-reader/no_op_config_reader.dart | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 lib/src/utils/config-reader/no_op_config_reader.dart diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index 4bd299a..d3aa78f 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -86,14 +86,8 @@ class Configuration { Log.startingTask(taskName); await _findAndSetCliPath(); - try { - final reader = ConfigReader(); - loadConfig(reader); - } catch (e) { - // Will catch an exception if no proper config could be found e.g sentry.properties or pubspec.yaml - Log.error(e.toString()); - return; - } + final reader = ConfigReader(); + loadConfig(reader); Log.taskCompleted(taskName); } diff --git a/lib/src/utils/config-reader/config_reader.dart b/lib/src/utils/config-reader/config_reader.dart index e9ccf60..18611a3 100644 --- a/lib/src/utils/config-reader/config_reader.dart +++ b/lib/src/utils/config-reader/config_reader.dart @@ -4,6 +4,7 @@ import 'package:file/file.dart'; import '../injector.dart'; import '../log.dart'; +import 'no_op_config_reader.dart'; import 'properties_config_reader.dart'; import 'yaml_config_reader.dart'; @@ -35,8 +36,8 @@ abstract class ConfigReader { Properties.fromString(propertiesFile.readAsStringSync()); return PropertiesConfigReader(properties); } - throw Exception( - 'no config found, please use sentry.properties or pubspec.yaml.'); + Log.error('no config found, please use sentry.properties or pubspec.yaml.'); + return NoOpConfigReader(); } static dynamic getPubspec() { diff --git a/lib/src/utils/config-reader/no_op_config_reader.dart b/lib/src/utils/config-reader/no_op_config_reader.dart new file mode 100644 index 0000000..e792e28 --- /dev/null +++ b/lib/src/utils/config-reader/no_op_config_reader.dart @@ -0,0 +1,20 @@ +import 'config_reader.dart'; + +class NoOpConfigReader implements ConfigReader { + NoOpConfigReader(); + + @override + bool? getBool(String key, {String? deprecatedKey}) { + return null; + } + + @override + String? getString(String key, {String? deprecatedKey}) { + return null; + } + + @override + bool contains(String key) { + return false; + } +}