Skip to content

fix(firestore): fix fetch connection error message - #10340

Open
dlarocque wants to merge 3 commits into
mainfrom
dl/fst-fetch-err
Open

fix(firestore): fix fetch connection error message#10340
dlarocque wants to merge 3 commits into
mainfrom
dl/fst-fetch-err

Conversation

@dlarocque

Copy link
Copy Markdown
Contributor

Fixes fetch connection error messages. We now read the thrown error's message and cause instead of attempting to read a potentially non-existent statusText from an Error object, preventing connection failures like ECONNREFUSED from being displayed as undefined.

In tests, we see errors like this

    145) Vectors
         can be read and written using the lite SDK:
       FirebaseError: [code=unknown]: Request failed with error: undefined

Now, they will look like this:

    145) Vectors
         can be read and written using the lite SDK:
       FirebaseError: [code=unknown]: Request failed with error: fetch
  failed (Error: connect ECONNREFUSED 127.0.0.1:8080)

This will also impact users.

Before:

    FirebaseError: [code=unknown]: Request failed with error: undefined

Now:

    FirebaseError: [code=unknown]: Request failed with error: fetch failed
  (ConnectTimeoutError: Connect Timeout Error)

@dlarocque
dlarocque requested review from a team as code owners August 31, 2026 17:14
@changeset-bot

changeset-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 31fb267

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/firestore Patch
firebase Patch
@firebase/firestore-compat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves error handling in FetchConnection for the browser-lite platform of Firestore by extracting more detailed error messages (including message and cause) when a fetch request fails. The review feedback points out a potential issue where err.message is undefined but err.cause is present, which would result in a string containing "undefined", and provides a code suggestion to handle this case safely.

Comment thread packages/firestore/src/platform/browser_lite/fetch_connection.ts

@MarkDuckworth MarkDuckworth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with question

const cause = err?.cause ? String(err.cause) : undefined;
const errorMessage =
(message && cause ? `${message} (${cause})` : (message ?? cause)) ??
err?.statusText ??

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have enough context on statusText but are there scenarios where either message or cause is defined but statusText still provides useful information, and therefore this change is a regression in surfacing error details?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't think statusText was ever defined on the error object. I think this code was copied from the block above, and response.statusText (valid) was replaced with err.statusText by mistake.

https://github.com/firebase/firebase-js-sdk/pull/3482/changes#diff-91ed949c8a1f344b8e3707a1607fe8e5c89b3b2db8ff4382a67ee52fe118b6d7R65-R76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants