Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(firestore): Change asserts to throw argumentError
  • Loading branch information
MichaelVerdon committed Apr 23, 2025
commit 9bb372a64ffd184ba0a324ef50e4331f9f104fd1
53 changes: 21 additions & 32 deletions packages/cloud_firestore/cloud_firestore/lib/src/firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,13 @@ class FirebaseFirestore extends FirebasePluginPlatform {

/// Gets a [CollectionReference] for the specified Firestore path.
CollectionReference<Map<String, dynamic>> collection(String collectionPath) {
assert(
collectionPath.isNotEmpty,
'a collectionPath path must be a non-empty string',
);
assert(
!collectionPath.contains('//'),
'a collection path must not contain "//"',
);
assert(
isValidCollectionPath(collectionPath),
'a collection path must point to a valid collection.',
);
if (collectionPath.isEmpty) {
throw ArgumentError('A collection path must be a non-empty string.');
} else if (collectionPath.contains('//')) {
throw ArgumentError('A collection path must not contain "//".');
} else if (!isValidCollectionPath(collectionPath)) {
throw ArgumentError('A collection path must point to a valid collection.');
}

return _JsonCollectionReference(this, _delegate.collection(collectionPath));
}
Expand Down Expand Up @@ -214,14 +209,13 @@ class FirebaseFirestore extends FirebasePluginPlatform {

/// Gets a [Query] for the specified collection group.
Query<Map<String, dynamic>> collectionGroup(String collectionPath) {
assert(
collectionPath.isNotEmpty,
'a collection path must be a non-empty string',
);
assert(
!collectionPath.contains('/'),
'a collection path passed to collectionGroup() cannot contain "/"',
);
if (collectionPath.isEmpty) {
throw ArgumentError('A collection path must be a non-empty string.');
}
if (collectionPath.contains('/')) {
throw ArgumentError(
'A collection path passed to collectionGroup() cannot contain "/".');
}

return _JsonQuery(this, _delegate.collectionGroup(collectionPath));
}
Expand All @@ -237,18 +231,13 @@ class FirebaseFirestore extends FirebasePluginPlatform {

/// Gets a [DocumentReference] for the specified Firestore path.
DocumentReference<Map<String, dynamic>> doc(String documentPath) {
assert(
documentPath.isNotEmpty,
'a document path must be a non-empty string',
);
assert(
!documentPath.contains('//'),
'a collection path must not contain "//"',
);
assert(
isValidDocumentPath(documentPath),
'a document path must point to a valid document.',
);
if (documentPath.isEmpty) {
throw ArgumentError('A document path must be a non-empty string.');
} else if (documentPath.contains('//')) {
throw ArgumentError('A document path must not contain "//".');
} else if (!isValidDocumentPath(documentPath)) {
throw ArgumentError('A document path must point to a valid document.');
}

return _JsonDocumentReference(this, _delegate.doc(documentPath));
}
Expand Down
Loading