diff --git a/CHANGELOG.md b/CHANGELOG.md index c68d7fefa..7bad81aeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * None ### Fixed -* None +* Creating an `AppConfiguration` with an empty appId will now throw an exception rather than crashing the app. (Issue [#1487](https://github.com/realm/realm-dart/issues/1487)) ### Compatibility * Realm Studio: 13.0.0 or later. diff --git a/lib/src/app.dart b/lib/src/app.dart index f603a5343..d22c0c729 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -157,7 +157,11 @@ class AppConfiguration { HttpClient? httpClient, }) : baseUrl = baseUrl ?? Uri.parse('https://realm.mongodb.com'), baseFilePath = baseFilePath ?? Directory(_path.dirname(Configuration.defaultRealmPath)), - httpClient = httpClient ?? _defaultClient; + httpClient = httpClient ?? _defaultClient { + if (appId == '') { + throw RealmException('Supplied appId must be a non-empty value'); + } + } } /// An [App] is the main client-side entry point for interacting with an [Atlas App Services](https://www.mongodb.com/docs/atlas/app-services/) application. diff --git a/test/app_test.dart b/test/app_test.dart index ab359d6eb..222d7bf3a 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -393,6 +393,10 @@ void main() { expect(log, contains('App constructor called on Isolate')); }); + + test('AppConfiguration(empty-id) throws', () { + expect(() => AppConfiguration(''), throwsA(isA())); + }); } extension PersonExt on Person {