Skip to content

Commit 43f0036

Browse files
author
Brian Chen
authored
Port android error messages over (#1924)
1 parent 857b0fe commit 43f0036

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

packages/firestore/src/api/database.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,9 +1894,8 @@ export class Query implements firestore.Query {
18941894
if (documentIdValue === '') {
18951895
throw new FirestoreError(
18961896
Code.INVALID_ARGUMENT,
1897-
'Function Query.where() requires its third parameter to be a ' +
1898-
'valid document ID if the first parameter is ' +
1899-
'FieldPath.documentId(), but it was an empty string.'
1897+
'Invalid query. When querying with FieldPath.documentId(), you ' +
1898+
'must provide a valid document ID, but it was an empty string.'
19001899
);
19011900
}
19021901
if (
@@ -1905,9 +1904,9 @@ export class Query implements firestore.Query {
19051904
) {
19061905
throw new FirestoreError(
19071906
Code.INVALID_ARGUMENT,
1908-
`Invalid third parameter to Query.where(). When querying a collection by ` +
1909-
`FieldPath.documentId(), the value provided must be a plain document ID, but ` +
1910-
`'${documentIdValue}' contains a slash.`
1907+
`Invalid query. When querying a collection by ` +
1908+
`FieldPath.documentId(), you must provide a plain document ID, but ` +
1909+
`'${documentIdValue}' contains a '/' character.`
19111910
);
19121911
}
19131912
const path = this._query.path.child(
@@ -1916,7 +1915,7 @@ export class Query implements firestore.Query {
19161915
if (!DocumentKey.isDocumentKey(path)) {
19171916
throw new FirestoreError(
19181917
Code.INVALID_ARGUMENT,
1919-
`Invalid third parameter to Query.where(). When querying a collection group by ` +
1918+
`Invalid query. When querying a collection group by ` +
19201919
`FieldPath.documentId(), the value provided must result in a valid document path, ` +
19211920
`but '${path}' is not because it has an odd number of segments (${
19221921
path.length
@@ -1930,9 +1929,8 @@ export class Query implements firestore.Query {
19301929
} else {
19311930
throw new FirestoreError(
19321931
Code.INVALID_ARGUMENT,
1933-
`Function Query.where() requires its third parameter to be a ` +
1934-
`string or a DocumentReference if the first parameter is ` +
1935-
`FieldPath.documentId(), but it was: ` +
1932+
`Invalid query. When querying with FieldPath.documentId(), you must provide a valid ` +
1933+
`string or a DocumentReference, but it was: ` +
19361934
`${valueDescription(documentIdValue)}.`
19371935
);
19381936
}

packages/firestore/test/integration/api/validation.test.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,28 +1244,26 @@ apiDescribe('Validation:', (persistence: boolean) => {
12441244
expect(() =>
12451245
collection.where(FieldPath.documentId(), '>=', '')
12461246
).to.throw(
1247-
'Function Query.where() requires its third parameter to be ' +
1248-
'a valid document ID if the first parameter is ' +
1249-
'FieldPath.documentId(), but it was an empty string.'
1247+
'Invalid query. When querying with FieldPath.documentId(), you ' +
1248+
'must provide a valid document ID, but it was an empty string.'
12501249
);
12511250
expect(() =>
12521251
collection.where(FieldPath.documentId(), '>=', 'foo/bar/baz')
12531252
).to.throw(
1254-
`Invalid third parameter to Query.where(). When querying a collection by ` +
1255-
`FieldPath.documentId(), the value provided must be a plain document ID, but ` +
1256-
`'foo/bar/baz' contains a slash.`
1253+
`Invalid query. When querying a collection by ` +
1254+
`FieldPath.documentId(), you must provide a plain document ID, but ` +
1255+
`'foo/bar/baz' contains a '/' character.`
12571256
);
12581257
expect(() =>
12591258
collection.where(FieldPath.documentId(), '>=', 1)
12601259
).to.throw(
1261-
'Function Query.where() requires its third parameter to be ' +
1262-
'a string or a DocumentReference if the first parameter is ' +
1263-
'FieldPath.documentId(), but it was: 1.'
1260+
'Invalid query. When querying with FieldPath.documentId(), you must ' +
1261+
'provide a valid string or a DocumentReference, but it was: 1.'
12641262
);
12651263
expect(() =>
12661264
db.collectionGroup('foo').where(FieldPath.documentId(), '>=', 'foo')
12671265
).to.throw(
1268-
`Invalid third parameter to Query.where(). When querying a collection group by ` +
1266+
`Invalid query. When querying a collection group by ` +
12691267
`FieldPath.documentId(), the value provided must result in a valid document path, ` +
12701268
`but 'foo' is not because it has an odd number of segments (1).`
12711269
);
@@ -1299,31 +1297,29 @@ apiDescribe('Validation:', (persistence: boolean) => {
12991297
expect(() =>
13001298
collection.where(FieldPath.documentId(), inOp, [''])
13011299
).to.throw(
1302-
'Function Query.where() requires its third parameter to be ' +
1303-
'a valid document ID if the first parameter is ' +
1304-
'FieldPath.documentId(), but it was an empty string.'
1300+
'Invalid query. When querying with FieldPath.documentId(), you ' +
1301+
'must provide a valid document ID, but it was an empty string.'
13051302
);
13061303

13071304
expect(() =>
13081305
collection.where(FieldPath.documentId(), inOp, ['foo/bar/baz'])
13091306
).to.throw(
1310-
`Invalid third parameter to Query.where(). When querying a collection by ` +
1311-
`FieldPath.documentId(), the value provided must be a plain document ID, but ` +
1312-
`'foo/bar/baz' contains a slash.`
1307+
`Invalid query. When querying a collection by ` +
1308+
`FieldPath.documentId(), you must provide a plain document ID, but ` +
1309+
`'foo/bar/baz' contains a '/' character.`
13131310
);
13141311

13151312
expect(() =>
13161313
collection.where(FieldPath.documentId(), inOp, [1, 2])
13171314
).to.throw(
1318-
'Function Query.where() requires its third parameter to be ' +
1319-
'a string or a DocumentReference if the first parameter is ' +
1320-
'FieldPath.documentId(), but it was: 1.'
1315+
'Invalid query. When querying with FieldPath.documentId(), you must ' +
1316+
'provide a valid string or a DocumentReference, but it was: 1.'
13211317
);
13221318

13231319
expect(() =>
13241320
db.collectionGroup('foo').where(FieldPath.documentId(), inOp, ['foo'])
13251321
).to.throw(
1326-
`Invalid third parameter to Query.where(). When querying a collection group by ` +
1322+
`Invalid query. When querying a collection group by ` +
13271323
`FieldPath.documentId(), the value provided must result in a valid document path, ` +
13281324
`but 'foo' is not because it has an odd number of segments (1).`
13291325
);

0 commit comments

Comments
 (0)