Preserve plain-object rejection reasons in global error handlers#181
Open
Preserve plain-object rejection reasons in global error handlers#181
Conversation
neSpecc
reviewed
Apr 10, 2026
| * Prefers `.message` on objects, falls back to the value itself for strings, | ||
| * and serializes everything else. | ||
| * | ||
| * @param safeError - Sanitized error value (any shape) |
Member
There was a problem hiding this comment.
what does it meat "sanitized" in this context? Clarify it in the jsdoc please.
Also maybe sanitizedError?
| * @param fallbackValues - Fallback values from event if they can't be extracted from the error | ||
| * @returns A normalized `CapturedError` object | ||
| */ | ||
| export function fillCapturedError( |
Member
There was a problem hiding this comment.
Suggested change
| export function fillCapturedError( | |
| export function composeCapturedError( |
| event = event as ErrorEvent; | ||
|
|
||
| return fillCapturedError(event.error, { | ||
| title: event.message && `'${event.message}' at ${event.filename || '<unknown file>'}:${event.lineno}:${event.colno}`, |
Member
There was a problem hiding this comment.
is there any case when filename is undefined but lineno and colno are not?
Maybe they also can be undefined?
| }); | ||
| } | ||
|
|
||
| if (event.type === 'unhandledrejection') { |
Member
There was a problem hiding this comment.
to we need to lowercase event.type here?
| * @param error - event from which to get backtrace | ||
| */ | ||
| private async getBacktrace(error: Error | string): Promise<HawkJavaScriptEvent['backtrace']> { | ||
| private async getBacktrace(error: unknown): Promise<HawkJavaScriptEvent['backtrace']> { |
Member
There was a problem hiding this comment.
why unknown is better than exact union type?
| }); | ||
| } | ||
|
|
||
| return fillCapturedError(undefined); |
Member
There was a problem hiding this comment.
explain this case in comment and write a test for it
f3c071b to
f450310
Compare
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.
Closes #171
Fix global error normalization so plain-object promise rejection reasons are captured as readable payloads instead of "[object Object]".
PR Description
Fix error normalization for global error handlers so rejected plain objects are preserved instead of being collapsed into
"[object Object]".This PR introduces a normalized
CapturedErrorshape and uses it across the main catcher and console catcher. Forunhandledrejection, plain-object reasons are now serialized into a readable title instead of going throughString(obj). For browserErrorEvents, the catcher now also builds a more useful fallback message when the original error object is unavailable (for example, cross-origin script errors).Changes
fillCapturedErrorandgetErrorFromErrorEventhelpers insrc/utils/error.tsCatcherinternals fromError | stringto normalizedCapturedErrorconsoleCatcherrawErrorreference for deduplication/backtrace logicErrorDOMExceptionErrorEventfallback