Skip to content

fix(core): Resolve relative URLs when enhancing fetch error messages - #25555

Open
kunal649 wants to merge 4 commits into
getsentry:developfrom
kunal649:kunal/fix/fetch-error-relative-url
Open

kunal649 wants to merge 4 commits into
getsentry:developfrom
kunal649:kunal/fix/fetch-error-relative-url

Conversation

@kunal649

@kunal649 kunal649 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

enhanceFetchErrorMessages already adds the host to generic fetch errors, so Failed to fetch becomes Failed to fetch (example.com). The catch is that it ran new URL(url) with no base, and that throws for relative URLs like /api/foo or the fetch("") from the issue. The try/catch swallowed the error, so those requests never got the host.

Now relative URLs are resolved against location.href instead of origin to safely handle sandboxed iframes and opaque origins without throwing. Absolute URLs ignore the base, and where there's no location (Node, workers) nothing changes. I also skip the enhancement when the resolved host is empty, like on file:// pages, otherwise you'd get Failed to fetch (). location is added to InternalGlobal for the typing.

Added 7 unit tests (relative URL, empty URL, no location, file:// origin, a relative path & an absolute URL in sandboxed srcdoc iframe , absolute URL on another origin).

This only touches the error message. The empty URL in the fetch breadcrumbs is a separate spot, so I left it out to discuss on the issue thread.

Ref #13168

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit efe30f6. Configure here.

Comment thread packages/core/src/instrument/fetch.ts Outdated

@s1gr1d s1gr1d left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you so much for picking this up!

a small nit regarding the tests: they are all quite similar so you could use an it.each there, like this:

    it.each([
      ['a relative path', 'https://app.example.com/dashboard?tab=billing', '/api/users/42', 'Failed to fetch (app.example.com)'],
    ])('resolves %s against location.href', async (_name, href, target, expected) => {}

Comment thread packages/core/src/utils/worldwide.ts Outdated
@kunal649
kunal649 force-pushed the kunal/fix/fetch-error-relative-url branch from efe30f6 to dc615b1 Compare October 20, 2026 16:47
@s1gr1d s1gr1d changed the title fix(core) : Resolve relative URLs when enhancing fetch error messages fix(core): Resolve relative URLs when enhancing fetch error messages Oct 21, 2026

@s1gr1d s1gr1d left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good now, thank you!

A few small things:

  • Can you update the description so it mentions href?
  • We should rename Fixes #13168 -> Ref #13168. This PR covers the fetch error message, but the issue also mentions XHR and the empty URL in breadcrumbs, so we should keep that open

Comment thread packages/core/test/lib/instrument/fetch.test.ts
@kunal649
kunal649 force-pushed the kunal/fix/fetch-error-relative-url branch from dc615b1 to e776589 Compare October 21, 2026 16:14
@kunal649

Copy link
Copy Markdown
Contributor Author

Looks good now, thank you!

A few small things:

  • Can you update the description so it mentions href?
  • We should rename Fixes #13168 -> Ref #13168. This PR covers the fetch error message, but the issue also mentions XHR and the empty URL in breadcrumbs, so we should keep that open

Done, sigrid

@kunal649
kunal649 force-pushed the kunal/fix/fetch-error-relative-url branch from e776589 to 21feeb1 Compare October 21, 2026 16:55

@s1gr1d s1gr1d left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the updates! One last thing: the "Check file formatting" job fails on the new about:srcdoc row in fetch.test.ts (my suggestion was not properly, sorry 🙈). Running pnpm run format fixes it.

This branch has not been deployed

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

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants