Skip to content

feat: core ExtraErrorData integration #1778

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 2 commits into from
Dec 11, 2018
Merged

feat: core ExtraErrorData integration #1778

merged 2 commits into from
Dec 11, 2018

Conversation

kamilogorek
Copy link
Contributor

Fixes #1777 in a global manner, instead of piling more code in browser package.

TODO: Update https://docs.sentry.io/platforms/javascript/default-integrations/ after it gets merged

@kamilogorek kamilogorek requested a review from HazAT December 3, 2018 13:07
@getsentry-bot
Copy link
Contributor

getsentry-bot commented Dec 3, 2018

Warnings
⚠️ Please add a changelog entry for your changes.
Messages
📖 ✅ TSLint passed
📖 @sentry/browser gzip'ed minified size: 21.7148 kB

Generated by 🚫 dangerJS

Copy link
Contributor

@SimonSchick SimonSchick left a comment

Choose a reason for hiding this comment

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

Thanks for the swift action, just a few comments.

// We are trying to enhance already existing event, so no harm done if it won't succeed
try {
const name = error.name || error.constructor.name;
const errorKeys = Object.keys(error).filter(key => !(key in ['name', 'message', 'stack']));
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is copy/paste but the in operator usually doesn't work with arrays?

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, I believe this isn't really needed because Object.keys doesn't return name, message, and stack.
At the same time Object.keys doesn't capture properties such as lineNumber in firefox's SyntaxError.

Object.getOwnPropertyDescriptors might be better suited for fetching properties like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And you are totally right about in usage here, however, we should keep the filter in place, just fixed one. The issue here is that different browsers return different keys (how lovely, right? :p)

Chrome:
Object.keys: ["something"]
Object.getOwnPropertyDescriptors: {stack: {…}, message: {…}, something: {…}}

Firefox:
Object.keys: ["something"]
Object.getOwnPropertyDescriptors: { fileName: {…}, lineNumber: {…}, columnNumber: {…}, message: {…}, something: {…} }

Safari:
Object.keys: ["something", "line", "column"]
Object.getOwnPropertyDescriptors: {message: Object, something: Object, line: Object, column: Object, stack: Object}
var foo = new SyntaxError('asd');
foo.something = 42;
var nativeKeys = ['name', 'message', 'stack', 'line', 'column', 'fileName', 'lineNumber', 'columnNumber'];
Object.keys(foo).filter(key => nativeKeys.indexOf(key) === -1);

This seems to be the most unified way now.

* Just an Error object with arbitrary attributes attached to it.
*/
interface ExtendedError extends Error {
[key: string]: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what your TS version is, but you might want to use unknown.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, we never actually used unkown yet because we started with typescript < 3.
But it makes sense here.

}

return null;
} catch (_oO) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't that log debug data, just in case?

...errorData,
},
};
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

redundant else btw :)

@kamilogorek
Copy link
Contributor Author

Updated. Thanks for the review @SimonSchick!

@kamilogorek kamilogorek merged commit 2a43e94 into master Dec 11, 2018
@kamilogorek kamilogorek deleted the extra-error-data branch December 11, 2018 11:20
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.

4 participants