From 1c9d0605e8b37d81bb07438431aff9dc0b3e577f Mon Sep 17 00:00:00 2001 From: cherylEnkidu Date: Mon, 17 Nov 2025 11:08:18 -0500 Subject: [PATCH 1/7] Corrected misleading error message when doc() is called with undefined. --- packages/firestore/src/lite-api/reference.ts | 8 +++++++- packages/firestore/test/lite/integration.test.ts | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/firestore/src/lite-api/reference.ts b/packages/firestore/src/lite-api/reference.ts index f38dad9a078..5881f4fe983 100644 --- a/packages/firestore/src/lite-api/reference.ts +++ b/packages/firestore/src/lite-api/reference.ts @@ -627,6 +627,12 @@ export function doc( path?: string, ...pathSegments: string[] ): DocumentReference { + if (parent === undefined) { + throw new FirestoreError( + Code.INVALID_ARGUMENT, + 'Function doc() cannot be called with an undefined first argument.' + ); + } parent = getModularInstance(parent); // We allow omission of 'pathString' but explicitly prohibit passing in both @@ -651,7 +657,7 @@ export function doc( ) { throw new FirestoreError( Code.INVALID_ARGUMENT, - 'Expected first argument to collection() to be a CollectionReference, ' + + 'Expected first argument to doc() to be a CollectionReference, ' + 'a DocumentReference or FirebaseFirestore' ); } diff --git a/packages/firestore/test/lite/integration.test.ts b/packages/firestore/test/lite/integration.test.ts index 7fb7eafcb1e..cb1152a9715 100644 --- a/packages/firestore/test/lite/integration.test.ts +++ b/packages/firestore/test/lite/integration.test.ts @@ -285,6 +285,12 @@ describe('doc', () => { it('validates path', () => { return withTestDb(db => { + expect(() => doc(undefined as any, 'coll/doc')).to.throw( + 'Function doc() cannot be called with an empty first argument.' + ); + expect(() => doc({} as any, 'coll/doc')).to.throw( + 'Expected first argument to doc() to be a CollectionReference, a DocumentReference or FirebaseFirestore' + ); expect(() => doc(db, 'coll')).to.throw( 'Invalid document reference. Document references must have an even ' + 'number of segments, but coll has 1.' From 60f0c838452dadb505a145b9c4d81495d525ac86 Mon Sep 17 00:00:00 2001 From: cherylEnkidu Date: Mon, 17 Nov 2025 11:12:28 -0500 Subject: [PATCH 2/7] add changeset --- .changeset/thin-sheep-smoke.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/thin-sheep-smoke.md diff --git a/.changeset/thin-sheep-smoke.md b/.changeset/thin-sheep-smoke.md new file mode 100644 index 00000000000..83af71b0d0a --- /dev/null +++ b/.changeset/thin-sheep-smoke.md @@ -0,0 +1,5 @@ +--- +'@firebase/firestore': patch +--- + +Fix: Corrected misleading error message when doc() is called with undefined. From c12790982abaf803175666a7e8ae900a49789295 Mon Sep 17 00:00:00 2001 From: cherylEnkidu <96084918+cherylEnkidu@users.noreply.github.com> Date: Mon, 17 Nov 2025 11:14:44 -0500 Subject: [PATCH 3/7] Update packages/firestore/test/lite/integration.test.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/firestore/test/lite/integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firestore/test/lite/integration.test.ts b/packages/firestore/test/lite/integration.test.ts index cb1152a9715..5b193a255dd 100644 --- a/packages/firestore/test/lite/integration.test.ts +++ b/packages/firestore/test/lite/integration.test.ts @@ -286,7 +286,7 @@ describe('doc', () => { it('validates path', () => { return withTestDb(db => { expect(() => doc(undefined as any, 'coll/doc')).to.throw( - 'Function doc() cannot be called with an empty first argument.' + 'Function doc() cannot be called with an undefined first argument.' ); expect(() => doc({} as any, 'coll/doc')).to.throw( 'Expected first argument to doc() to be a CollectionReference, a DocumentReference or FirebaseFirestore' From 30962d21a57b9d33003ee99fd51993a7aa08eb81 Mon Sep 17 00:00:00 2001 From: cherylEnkidu Date: Mon, 17 Nov 2025 13:46:17 -0500 Subject: [PATCH 4/7] remove any --- packages/firestore/test/lite/integration.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/firestore/test/lite/integration.test.ts b/packages/firestore/test/lite/integration.test.ts index cb1152a9715..898d4f0bb9f 100644 --- a/packages/firestore/test/lite/integration.test.ts +++ b/packages/firestore/test/lite/integration.test.ts @@ -285,10 +285,10 @@ describe('doc', () => { it('validates path', () => { return withTestDb(db => { - expect(() => doc(undefined as any, 'coll/doc')).to.throw( + expect(() => doc(undefined, 'coll/doc')).to.throw( 'Function doc() cannot be called with an empty first argument.' ); - expect(() => doc({} as any, 'coll/doc')).to.throw( + expect(() => doc({}, 'coll/doc')).to.throw( 'Expected first argument to doc() to be a CollectionReference, a DocumentReference or FirebaseFirestore' ); expect(() => doc(db, 'coll')).to.throw( From e7262aa7739b634f594b28a06e3b93d4f3cd320d Mon Sep 17 00:00:00 2001 From: cherylEnkidu Date: Tue, 18 Nov 2025 09:59:15 -0500 Subject: [PATCH 5/7] add ts-ignore --- packages/firestore/test/lite/integration.test.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/firestore/test/lite/integration.test.ts b/packages/firestore/test/lite/integration.test.ts index cb4d510d9ab..dd0c5a09d69 100644 --- a/packages/firestore/test/lite/integration.test.ts +++ b/packages/firestore/test/lite/integration.test.ts @@ -285,10 +285,16 @@ describe('doc', () => { it('validates path', () => { return withTestDb(db => { - expect(() => doc(undefined, 'coll/doc')).to.throw( - 'Function doc() cannot be called with an undefined first argument.' + expect(() => + // @ts-ignore + doc(undefined, 'coll/doc') + ).to.throw( + 'Function doc() cannot be called with an empty first argument.' ); - expect(() => doc({}, 'coll/doc')).to.throw( + expect(() => + // @ts-ignore + doc({}, 'coll/doc') + ).to.throw( 'Expected first argument to doc() to be a CollectionReference, a DocumentReference or FirebaseFirestore' ); expect(() => doc(db, 'coll')).to.throw( From 0e0e8f9fa3a785663fe567966eb8d1454f44405a Mon Sep 17 00:00:00 2001 From: cherylEnkidu Date: Tue, 18 Nov 2025 10:17:14 -0500 Subject: [PATCH 6/7] fix error message --- packages/firestore/test/lite/integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firestore/test/lite/integration.test.ts b/packages/firestore/test/lite/integration.test.ts index dd0c5a09d69..95b5bfb9425 100644 --- a/packages/firestore/test/lite/integration.test.ts +++ b/packages/firestore/test/lite/integration.test.ts @@ -289,7 +289,7 @@ describe('doc', () => { // @ts-ignore doc(undefined, 'coll/doc') ).to.throw( - 'Function doc() cannot be called with an empty first argument.' + 'Function doc() cannot be called with an undefined first argument.' ); expect(() => // @ts-ignore From 3124bc94074fa490516bfa16c5170d52ad10e517 Mon Sep 17 00:00:00 2001 From: cherylEnkidu Date: Tue, 18 Nov 2025 12:30:26 -0500 Subject: [PATCH 7/7] improve code --- packages/firestore/src/lite-api/reference.ts | 6 ------ packages/firestore/test/lite/integration.test.ts | 8 +------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/firestore/src/lite-api/reference.ts b/packages/firestore/src/lite-api/reference.ts index 5881f4fe983..e6c5fd7b056 100644 --- a/packages/firestore/src/lite-api/reference.ts +++ b/packages/firestore/src/lite-api/reference.ts @@ -627,12 +627,6 @@ export function doc( path?: string, ...pathSegments: string[] ): DocumentReference { - if (parent === undefined) { - throw new FirestoreError( - Code.INVALID_ARGUMENT, - 'Function doc() cannot be called with an undefined first argument.' - ); - } parent = getModularInstance(parent); // We allow omission of 'pathString' but explicitly prohibit passing in both diff --git a/packages/firestore/test/lite/integration.test.ts b/packages/firestore/test/lite/integration.test.ts index 95b5bfb9425..54595ade4d4 100644 --- a/packages/firestore/test/lite/integration.test.ts +++ b/packages/firestore/test/lite/integration.test.ts @@ -286,13 +286,7 @@ describe('doc', () => { it('validates path', () => { return withTestDb(db => { expect(() => - // @ts-ignore - doc(undefined, 'coll/doc') - ).to.throw( - 'Function doc() cannot be called with an undefined first argument.' - ); - expect(() => - // @ts-ignore + // @ts-expect-error doc({}, 'coll/doc') ).to.throw( 'Expected first argument to doc() to be a CollectionReference, a DocumentReference or FirebaseFirestore'