Skip to content
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

Fix bad message pulled from thrown strings and objects #872

Merged
merged 3 commits into from
Mar 3, 2017

Conversation

benvinegar
Copy link
Contributor

@benvinegar benvinegar commented Feb 28, 2017

Fixes #871

At some point browsers must have started sending the 5th argument to window.onerror for non-errors (Safari 10+? Chrome X?), which is why this error popped up in the past year and not before.

cc @getsentry/javascript

@@ -26,7 +26,7 @@ var _slice = [].slice;
var UNKNOWN_FUNCTION = '?';

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types
var ERROR_TYPES_RE = /^(?:Uncaught (?:exception: )?)?((?:Eval|Internal|Range|Reference|Syntax|Type|URI)Error): ?(.*)$/;
var ERROR_TYPES_RE = /^(?:Uncaught (?:exception: )?)?((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): ?(.*)$/;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was not matching on just Error, e.g. throw new Error('test').

Copy link
Contributor

Choose a reason for hiding this comment

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

would be kind of nice to have unit tests for this regex as kinda-documentation, but i don't think its important and the other tests cover it

@@ -26,7 +26,7 @@ var _slice = [].slice;
var UNKNOWN_FUNCTION = '?';

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types
var ERROR_TYPES_RE = /^(?:Uncaught (?:exception: )?)?((?:Eval|Internal|Range|Reference|Syntax|Type|URI)Error): ?(.*)$/;
var ERROR_TYPES_RE = /^(?:Uncaught (?:exception: )?)?((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): ?(.*)$/;
Copy link
Contributor

Choose a reason for hiding this comment

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

would be kind of nice to have unit tests for this regex as kinda-documentation, but i don't think its important and the other tests cover it

@benvinegar
Copy link
Contributor Author

would be kind of nice to have unit tests for this regex as kinda-documentation

It's partially covered here:

https://github.com/getsentry/raven-js/blob/master/test/vendor/tracekit.test.js#L151

Copy link
Contributor

@LewisJEllis LewisJEllis left a comment

Choose a reason for hiding this comment

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

Seems reasonable, but might further consider case where onerror receives a string as 5th argument. Don't know if/how often that happens in wild though.

@@ -152,7 +152,11 @@ TraceKit.report = (function reportModuleWrapper() {
if (lastExceptionStack) {
TraceKit.computeStackTrace.augmentStackTraceWithInitialElement(lastExceptionStack, url, lineNo, message);
processLastException();
} else if (ex) {
} else if (ex && typeof ex === 'object') {
Copy link
Contributor

@LewisJEllis LewisJEllis Mar 1, 2017

Choose a reason for hiding this comment

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

Couldn't we end up with a string (or even an error-like string) here? This prints "string":

window.onerror = function (message, filename, lineno, colno, ex) {
  console.log(typeof ex);
};

var x = "hello";
x.stack = ['a'];
throw x;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but we didn't handle that case either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But you did remind me of one thing, which is that you could do throw new String('lol') that would evaluate as an object.

Gonna revisit.

@benvinegar benvinegar changed the title Fix bad message pulled from thrown strings Fix bad message pulled from thrown strings and objects Mar 1, 2017
@benvinegar
Copy link
Contributor Author

Okay, the scope of this has increased once I realized there was a gap in coverage.

It now covers both uncaught thrown strings AND objects.

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.

3 participants