Skip to content

Commit 8288352

Browse files
committed
refactor(remote_config): throw ArgumentError with more verbose description
1 parent eeaab8a commit 8288352

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,15 @@ class RemoteConfig extends FirebasePluginPlatform with ChangeNotifier {
134134
/// Sets the default parameter values for the current instance.
135135
/// Only booleans, strings and numbers are supported as values of the map
136136
Future<void> setDefaults(Map<String, dynamic> defaultParameters) {
137-
defaultParameters.values.forEach(_checkIsSupportedType);
137+
defaultParameters.forEach(_checkIsSupportedType);
138138
return _delegate.setDefaults(defaultParameters);
139139
}
140140

141-
void _checkIsSupportedType(dynamic value) {
141+
void _checkIsSupportedType(String key, dynamic value) {
142142
if (value is! bool && value is! num && value is! String) {
143-
throw Exception(
144-
'Non-primitive types are not supported as config values. '
143+
throw ArgumentError(
144+
'Invalid value type "${value.runtimeType}" for key "$key". '
145+
'Only booleans, numbers and strings are supported as config values. '
145146
"If you're trying to pass a json object – convert it to string beforehand",
146147
);
147148
}

packages/firebase_remote_config/firebase_remote_config/test/firebase_remote_config_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void main() {
219219
() => remoteConfig.setDefaults({
220220
'key': {'nested': 'object'}
221221
}),
222-
throwsException,
222+
throwsArgumentError,
223223
);
224224
});
225225
});

0 commit comments

Comments
 (0)