Skip to content

fix: handle URL/Request objects in fetch interceptor + null-safe Linear formatting (#3)#4

Merged
NicoKaempf merged 1 commit into
mainfrom
fix/network-url-undefined-issue-3
Jun 17, 2026
Merged

fix: handle URL/Request objects in fetch interceptor + null-safe Linear formatting (#3)#4
NicoKaempf merged 1 commit into
mainfrom
fix/network-url-undefined-issue-3

Conversation

@NicoKaempf

Copy link
Copy Markdown
Contributor

Fixes #3

Problem

Submitting a bug report crashed server-side with a 500 whenever the captured network history contained a request issued via fetch(new URL(...)) (a URL object as the first fetch argument). This happens reliably in production with an absolute base URL (e.g. Better Auth / @better-fetch/fetch), because those calls go through the patched global fetch and were recorded with url: undefined.

TypeError: Cannot read properties of undefined (reading 'length')
    at formatBugReportForLinear (runtime/utils/linearApi.js)

Two independent defects, both addressed (defense in depth):

1. Capture — URL/Request not handled (src/runtime/utils/networkRequests.ts)

fetch() accepts string | URL | Request. A URL exposes .href, not .url, so args[0].url was undefined. The fetch path is now aligned with the already-correct XHR path. As a bonus, options was previously set to the URL object itself — now correctly taken from args[1] (or the Request for Request inputs).

2. Formatting — not null-safe → 500 (src/runtime/utils/linearApi.ts)

req.url (network table + failed-requests list) and event.target (user journey) are now read null-safe, so an undefined value no longer throws inside Array.map. This also guards external/legacy posts.

Tests

  • test/utils/networkRequests.test.ts (new): capture coverage for URL / string / Request inputs.
  • test/utils/linearApi.test.ts: regression coverage for missing url / target.
  • Full suite: 56 tests green, prepack build successful.

🤖 Generated with Claude Code

…ar formatting (#3)

The patched global fetch read args[0].url, but fetch() accepts string | URL |
Request. A URL object exposes .href (not .url), so requests issued via
fetch(new URL(...)) — e.g. Better Auth / @better-fetch/fetch with an absolute
baseURL — were recorded with url: undefined. formatBugReportForLinear then
crashed with a 500 (Cannot read properties of undefined reading 'length')
during issue formatting.

- networkRequests.ts: resolve url for string/URL/Request inputs, mirroring the
  XHR path; take options from the Request itself when applicable.
- linearApi.ts: null-safe access for req.url and event.target (defense in depth,
  also guards external/legacy posts).
- tests: regression coverage for capture (URL/string/Request) and formatting.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI 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.

Pull request overview

Fixes a production crash when bug reports include captured fetch() requests made with URL/Request inputs, and hardens Linear issue formatting against missing fields to prevent server-side 500s.

Changes:

  • Update the fetch interceptor to correctly resolve the request URL for string | URL | Request inputs and to derive options from the right source.
  • Make formatBugReportForLinear null-safe for networkRequests[].url and userInteractions[].target to avoid runtime exceptions.
  • Add regression tests covering URL/Request capture and null-safe Linear formatting.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/runtime/utils/networkRequests.ts Fixes fetch URL/options extraction for URL/Request inputs.
src/runtime/utils/linearApi.ts Guards formatting against missing url/target values.
test/utils/networkRequests.test.ts Adds tests for fetch capture with URL, string, and Request.
test/utils/linearApi.test.ts Adds regression tests ensuring formatting doesn’t throw on missing fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +90 to +96
const first = args[0]
const url
= typeof first === 'string'
? first
: first instanceof URL
? first.href
: first?.url ?? ''
@NicoKaempf NicoKaempf merged commit 594176a into main Jun 17, 2026
1 check passed
@pascal-klesse

Copy link
Copy Markdown
Member

🎉 This PR is included in version 1.6.8 🎉

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fetch(URL) in network interceptor records url:undefined → 500 in formatBugReportForLinear (req.url.length)

3 participants