-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Add option to enhance the fetch error message #18466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
size-limit report 📦
|
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
Lms24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me! Let's make sure to document the new option, thanks!
dev-packages/browser-integration-tests/suites/errors/fetch-enhance-messages-off/test.ts
Outdated
Show resolved
Hide resolved
dev-packages/browser-integration-tests/suites/errors/fetch-enhance-messages-off/test.ts
Outdated
Show resolved
Hide resolved
dev-packages/browser-integration-tests/suites/errors/fetch-enhance-messages-off/test.ts
Outdated
Show resolved
Hide resolved
dev-packages/browser-integration-tests/suites/errors/fetch-enhance-messages-report-only/test.ts
Outdated
Show resolved
Hide resolved
dev-packages/browser-integration-tests/suites/errors/fetch-enhance-messages-report-only/test.ts
Outdated
Show resolved
Hide resolved
dev-packages/browser-integration-tests/suites/errors/fetch-enhance-messages-report-only/test.ts
Outdated
Show resolved
Hide resolved
|
(I was thinking for a moment if it makes sense for us to only add the option to the |
…ance-messages-off/test.ts Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
…ance-messages-off/test.ts Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
…ance-messages-report-only/test.ts Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
…ance-messages-off/test.ts Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
…ance-messages-report-only/test.ts Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
…ance-messages-report-only/test.ts Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
0350acc to
308c1f2
Compare
| const enhanceOption = client?.getOptions().enhanceFetchErrorMessages ?? 'always'; | ||
| const shouldEnhance = enhanceOption !== false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: client?.getOptions() can be undefined, but the subsequent access to .enhanceFetchErrorMessages is not optional, causing a TypeError if no client is available.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
In packages/core/src/instrument/fetch.ts, the code attempts to access enhanceFetchErrorMessages on the result of client?.getOptions(). The getClient() function can return undefined, in which case client?.getOptions() also returns undefined. The subsequent property access is not using optional chaining (?.), leading to an attempt to read a property on undefined. This will throw a TypeError, causing the fetch instrumentation to crash whenever the SDK client is not available (e.g., before initialization or when disabled).
💡 Suggested Fix
Use optional chaining for the entire property access path to safely handle cases where the client or options are undefined. Change the line to const enhanceOption = client?.getOptions()?.enhanceFetchErrorMessages ?? 'always'; to prevent the TypeError.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: packages/core/src/instrument/fetch.ts#L118-L119
Potential issue: In `packages/core/src/instrument/fetch.ts`, the code attempts to access
`enhanceFetchErrorMessages` on the result of `client?.getOptions()`. The `getClient()`
function can return `undefined`, in which case `client?.getOptions()` also returns
`undefined`. The subsequent property access is not using optional chaining (`?.`),
leading to an attempt to read a property on `undefined`. This will throw a `TypeError`,
causing the fetch instrumentation to crash whenever the SDK client is not available
(e.g., before initialization or when disabled).
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7704468
(closes #18449)
(closes JS-1281)
Problem
As of now, the user has no chance to disallow the manipulation of fetch errors, as we overwrite the error. This can cause problems as seen in #18449.
Solution
This adds a new option for the SDK (please be very critical about that new option here, since
fetchhas no integration this has to be added as ainitoption).alwaysis the default and acts the same as it is now, so it is acting as feature:To give the user full control of how the errors are done there are 3 settings:
Special attention to reviewers
When having
report-onlythe generated logs locally differ from the ones in Sentry. I am not quite sure if that would cause any problems. This is the only question which I don't have the answer to yetAlternative
In case the size increase is too much, we can also have a boolean that disables that (which is on by default)