Title: "Non-Error exception captured with keys: [...]" due to invalid error instanceof check · Issue #6332 · getsentry/sentry-javascript · GitHub
Open Graph Title: "Non-Error exception captured with keys: [...]" due to invalid error instanceof check · Issue #6332 · getsentry/sentry-javascript
X Title: "Non-Error exception captured with keys: [...]" due to invalid error instanceof check · Issue #6332 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/6332
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"\"Non-Error exception captured with keys: [...]\" due to invalid error instanceof check","articleBody":"### Is there an existing issue for this?\n\n- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [X] I have reviewed the documentation https://docs.sentry.io/\n- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSelf-hosted/on-premise\n\n### Which package are you using?\n\n@sentry/angular\n\n### SDK Version\n\n7.7.0\n\n### Framework Version\n\nAngular 13.3 & Ionic 5\n\n### Link to Sentry event\n\n_No response_\n\n### Steps to Reproduce\n\n```typescript\r\n// Case1: capture string\r\nSentry.captureException('foo);\r\n\r\n// Case2: capture error-like object\r\nSentry.captureException({\r\n name: 'FooError',\r\n message: 'foo',\r\n});\r\n\r\n// Case3: throw string\r\nthrow 'foo';\r\n\r\n// Case4: throw error-like object\r\nthrow {\r\n name: 'FooError',\r\n message: 'foo',\r\n};\r\n\r\n// Case5: capture string with the SentryAngular ErrorHandler\r\nthis.errorHandler.handleError('foo');\r\n\r\n// Case6: capture error-like object with the SentryAngular ErrorHandler\r\nthis.errorHandler.handleError({\r\n name: 'FooError',\r\n message: 'foo',\r\n});\r\n```\n\n### Expected Result\n\nThe first problem I identify here is the incorrect handling of _error like_ objects. I suspect this is due to [this line](https://github.com/getsentry/sentry-javascript/blob/master/packages/angular/src/errorhandler.ts#L98):\r\n\r\n```typescript\r\n if (typeof error === 'string' || error instanceof Error) {\r\n return error;\r\n }\r\n```\r\n\r\nI am really not convinced an `instanceof` should be used here. Having a type guard to check for an error like object (it could also have a quick instanceof under the hood), would make more sense and also be more in line with the philosophy of TypeScript where types are checked as structures, instead of instances.\r\n\r\n\u003chr/>\r\n\r\nThe second problem I see is the difference of handling when an error is thrown, captured by Sentry manually or passed to the error handler.\r\n\r\nThat there is a difference between `Sentry.captureException()` and `ErrorHandler.handle()` makes sense since the latter is using the former under the hood. But I think having a difference of handling for when an error is thrown instead of passed to the error handler is a lot more surprising.\r\n\r\nI however could not find where the global listener is registered and check the problematic code or figure out a way to fix this.\n\n### Actual Result\n\n// Case1: capture string\r\nNothing captured!\r\n\r\n// Case2: capture error-like object\r\n```\r\ncaptureException\r\nNon-Error exception captured with keys: message, name\r\n```\r\n\r\n// Case3: throw string\r\nNothing captured!\r\n\r\n// Case4: throw error-like object\r\n```\r\nError resolvePromise(polyfills)\r\nUncaught (in promise): Object: {\"name\":\"FooError\",\"message\":\"foo\"}\r\n```\r\n\r\n// Case5: capture string with the SentryAngular ErrorHandler\r\nNothing captured!\r\n\r\n// Case6: capture error-like object with the SentryAngular ErrorHandler\r\nNothing captured!","author":{"url":"https://github.com/theofidry","@type":"Person","name":"theofidry"},"datePublished":"2022-11-29T14:24:22Z","url":"https://github.com/getsentry/sentry-javascript/issues/6332"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:192a1594-f7ac-08a0-d321-30e5154320e0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8244:232DFC:2659C02:321F7CD:6B042487 |
| html-safe-nonce | 70e0f0f50f62c704e023edae348e280b0fcd18776aab7be2b7e0c595a2467e3e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjQ0OjIzMkRGQzoyNjU5QzAyOjMyMUY3Q0Q6NkIwNDI0ODciLCJ2aXNpdG9yX2lkIjoiNDkyNjU0MjI0Mjk2NzIwMDkwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0857bcea35340ad0f10ddae54305b46ba64003f5abd09491a98db283bf8600d2 |
| hovercard-subject-tag | issue:1468154008 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/6332/issue_layout |
| twitter:image | https://opengraph.githubassets.com/393d8a7057cd13395e0f22c19fbe9ced1c6de66a648ca40f2c310b0302765377/getsentry/sentry-javascript/issues/6332 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/393d8a7057cd13395e0f22c19fbe9ced1c6de66a648ca40f2c310b0302765377/getsentry/sentry-javascript/issues/6332 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | theofidry |
| hostname | github.com |
| expected-hostname | github.com |
| None | f8d9f404447ab5df341c8a92cf5fc927730ad1321e64ac57656444d2438097f1 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f7edccce04851591ee529948701779ce6819bc53 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width