Skip to content

Commit

Permalink
fix: Make sure that falsy values are captured in unhandledrejections
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Aug 19, 2019
1 parent 836b31f commit 7f58251
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 165 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased

- [browser] feat: Use framesToPop for InvaliantViolations in React errors (#2204)
- [browser] fix: Make sure that falsy values are captured in unhandledrejections (#2207)
- [loader] fix: Loader should also retrigger falsy values as errors (#2207)

## 5.6.1

Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class GlobalHandlers implements Integration {
message.error && isString(message.error.message) ? message.error.message : 'No error message';
}

if (stacktrace.mechanism === 'onunhandledrejection' && stacktrace.incomplete) {
if (stacktrace.mechanism === 'onunhandledrejection' && (stacktrace.incomplete || stacktrace.mode === 'failed')) {
return this._eventFromIncompleteRejection(stacktrace, error);
}

Expand Down Expand Up @@ -166,8 +166,8 @@ export class GlobalHandlers implements Integration {
if (event.exception.values && event.exception.values[0]) {
event.exception.values[0].mechanism = {
data: {
incomplete: true,
mode: stacktrace.mode,
...(stacktrace.incomplete && { incomplete: stacktrace.incomplete }),
...(stacktrace.message && { message: stacktrace.message }),
...(stacktrace.name && { name: stacktrace.name }),
},
Expand Down
11 changes: 8 additions & 3 deletions packages/browser/src/tracekit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,12 @@ TraceKit._report = (function reportModuleWrapper() {
* @see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
*/
function _traceKitWindowOnUnhandledRejection(e: any) {
var err = e && typeof e.reason !== 'undefined' ? e.reason : e;
var err = e;
// You cannot itterate over non-objects, but we want to check
// for the existence in any value, not for the value itself
try {
err = e && 'reason' in e ? e.reason : e;
} catch (_oO) {}
var stack = TraceKit._computeStackTrace(err);
stack.mechanism = 'onunhandledrejection';
_notifyHandlers(stack, true, err);
Expand Down Expand Up @@ -906,8 +911,8 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() {

return {
original: ex,
name: ex.name,
message: ex.message,
name: ex && ex.name,
message: ex && ex.message,
mode: 'failed',
};
}
Expand Down

0 comments on commit 7f58251

Please sign in to comment.