-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: Exception type/value, Loader promise reject #1838
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
Conversation
@@ -23,6 +23,7 @@ export interface StackTrace { | |||
url: string; | |||
stack: StackFrame[]; | |||
useragent: string; | |||
original?: string; |
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.
Had to add this, since there is no other way to get the promise "string" otherwise.
See also: https://github.com/getsentry/sentry-javascript/pull/1838/files#diff-c3aa68526c753b964239284a89d48813R1472
type: stacktrace.name, | ||
value: stacktrace.message, | ||
}; | ||
|
||
if (frames && frames.length) { |
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.
It's better for the exception to not have stacktrace
as a key at all if we do not have any frames.
} else if (data[i].p) { | ||
SDK.captureException(data[i].p); | ||
} else if (data[i].p && tracekitUnhandledRejectionHandler) { | ||
tracekitUnhandledRejectionHandler.apply(_window, [data[i].p]); |
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.
Why do we I need to pass [data[i].p]
as an array here?
If I don't do this it doesn't work. This is my only question 🤔
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.
It's because data[i].e
, is an array of arguments retrieved from onerror
handler, where data[i].p
is a rejection.reason
attribute itself. apply
always accepts an array as the second argument. It can be changed to tracekitUnhandledRejectionHandler.call(_window, data[i].p);
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.
We can modify
sentry-javascript/packages/browser/src/loader.js
Lines 183 to 200 in a6176f5
var _oldOnerror = _window[_onerror]; | |
_window[_onerror] = function(message, source, lineno, colno, exception) { | |
// Use keys as "data type" to save some characters" | |
queue({ | |
e: [].slice.call(arguments) | |
}); | |
if (_oldOnerror) _oldOnerror.apply(_window, arguments); | |
}; | |
// Do the same store/queue/call operations for `onunhandledrejection` event | |
var _oldOnunhandledrejection = _window[_onunhandledrejection]; | |
_window[_onunhandledrejection] = function(exception) { | |
queue({ | |
p: exception.reason | |
}); | |
if (_oldOnunhandledrejection) _oldOnunhandledrejection.apply(_window, arguments); | |
}; |
Generated by 🚫 dangerJS |
} else if (data[i].p) { | ||
SDK.captureException(data[i].p); | ||
} else if (data[i].p && tracekitUnhandledRejectionHandler) { | ||
tracekitUnhandledRejectionHandler.apply(_window, [data[i].p]); |
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.
It's because data[i].e
, is an array of arguments retrieved from onerror
handler, where data[i].p
is a rejection.reason
attribute itself. apply
always accepts an array as the second argument. It can be changed to tracekitUnhandledRejectionHandler.call(_window, data[i].p);
} else if (data[i].p) { | ||
SDK.captureException(data[i].p); | ||
} else if (data[i].p && tracekitUnhandledRejectionHandler) { | ||
tracekitUnhandledRejectionHandler.apply(_window, [data[i].p]); |
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.
We can modify
sentry-javascript/packages/browser/src/loader.js
Lines 183 to 200 in a6176f5
var _oldOnerror = _window[_onerror]; | |
_window[_onerror] = function(message, source, lineno, colno, exception) { | |
// Use keys as "data type" to save some characters" | |
queue({ | |
e: [].slice.call(arguments) | |
}); | |
if (_oldOnerror) _oldOnerror.apply(_window, arguments); | |
}; | |
// Do the same store/queue/call operations for `onunhandledrejection` event | |
var _oldOnunhandledrejection = _window[_onunhandledrejection]; | |
_window[_onunhandledrejection] = function(exception) { | |
queue({ | |
p: exception.reason | |
}); | |
if (_oldOnunhandledrejection) _oldOnunhandledrejection.apply(_window, arguments); | |
}; |
This PR makes sure the
exception
always has type/value also for promise rejections with string.Additionally, it fixes the loader so it unhandled promises also go through tracekit instead of
captureException
.Fixes: #1824