10000 fix: Exception type/value, Loader promise reject by HazAT · Pull Request #1838 · getsentry/sentry-javascript · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 5 commits into from
Jan 16, 2019

Conversation

HazAT
Copy link
Member
@HazAT HazAT commented Jan 16, 2019

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

@HazAT HazAT self-assigned this Jan 16, 2019
@HazAT HazAT requested a review from kamilogorek as a code owner January 16, 2019 09:02
@@ -23,6 +23,7 @@ export interface StackTrace {
url: string;
stack: StackFrame[];
useragent: string;
original?: string;
Copy link
Member Author

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) {
Copy link
Member Author

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]);
Copy link
Member Author

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 🤔

Copy link
Contributor

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);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can modify

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);
};
to store all arguments as well and apply them in the same manner if we want to unify this

@getsentry-bot
Copy link
Contributor
getsentry-bot commented Jan 16, 2019
Messages
📖 ✅ TSLint passed
📖 @sentry/browser gzip'ed minified size: 22.2637 kB

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]);
Copy link
Contributor

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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can modify

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);
};
to store all arguments as well and apply them in the same manner if we want to unify this

@HazAT HazAT merged commit afe627e into master Jan 16, 2019
@HazAT HazAT deleted the fix/exception-promise-reject branch January 16, 2019 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chrome: <unlabled event> being sent when unhandledrejection occurs
3 participants
0