fix: handle URL/Request objects in fetch interceptor + null-safe Linear formatting (#3)#4
Merged
Merged
Conversation
…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>
There was a problem hiding this comment.
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 | Requestinputs and to derive options from the right source. - Make
formatBugReportForLinearnull-safe fornetworkRequests[].urlanduserInteractions[].targetto 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 ?? '' |
Member
|
🎉 This PR is included in version 1.6.8 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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(...))(aURLobject as the firstfetchargument). This happens reliably in production with an absolute base URL (e.g. Better Auth /@better-fetch/fetch), because those calls go through the patched globalfetchand were recorded withurl: undefined.Two independent defects, both addressed (defense in depth):
1. Capture —
URL/Requestnot handled (src/runtime/utils/networkRequests.ts)fetch()acceptsstring | URL | Request. AURLexposes.href, not.url, soargs[0].urlwasundefined. The fetch path is now aligned with the already-correct XHR path. As a bonus,optionswas previously set to theURLobject itself — now correctly taken fromargs[1](or theRequestforRequestinputs).2. Formatting — not null-safe → 500 (
src/runtime/utils/linearApi.ts)req.url(network table + failed-requests list) andevent.target(user journey) are now read null-safe, so anundefinedvalue no longer throws insideArray.map. This also guards external/legacy posts.Tests
test/utils/networkRequests.test.ts(new): capture coverage forURL/ string /Requestinputs.test/utils/linearApi.test.ts: regression coverage for missingurl/target.prepackbuild successful.🤖 Generated with Claude Code