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

[BUG] Error cause not being respected #17

Open
mmkal opened this issue Jan 26, 2024 · 4 comments
Open

[BUG] Error cause not being respected #17

mmkal opened this issue Jan 26, 2024 · 4 comments
Assignees

Comments

@mmkal
Copy link

mmkal commented Jan 26, 2024

🐞 Bug report

Description

We are calling Sentry.report(new Error('Something bad happened'), {cause: 'Some useful context about the bad thing'}) on a micro-sentry client, but we only see the "Something bad happened" message in sentry.io. I would expect the cause to appear under the "extras" section in the Sentry UI. It's not in the JSON payload sent to sentry a all though

Reproduction

I don't know that it's possible to reproduce in stackblitz since it's about what gets sent to sentry, but it should be easy to reproduce if you have a local sentry set up. Just create a new @micro-sentry/browser client and call the code snippet above.

Expected behavior

Include cause (MDN docs)

Versions

If needed:

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Angular/React/Vue [e.g. Angular 11]

Additional context

@sevaru sevaru assigned sevaru and unassigned MarsiBarsi Jan 29, 2024
@mmkal
Copy link
Author

mmkal commented Jan 30, 2024

For anyone else who gets this, here's a workaround: just extend the class, so you can use the protected send method:

import {BrowserMicroSentryClient as Base} from '@micro-sentry/browser'

class BrowserMicroSentryClient extends Base {
  report(error: Error) {
    const prepared = this.prepare(error)
    prepared.extra ||= {}
    prepared.extra.cause ||= error.cause
    Object.assign(prepared.extra, error)
    this.send(prepared)
  }
}

(the Object.assign adds anything else hanging off the Error object - what the official Sentry client does too)

@splincode
Copy link
Member

Could you open pull request?

@mmkal
Copy link
Author

mmkal commented Feb 7, 2024

I opened #18 with the workaround we're using, but it probably isn't up to scratch/mergeable - I haven't looked into docs/tests etc. But feel free to push to that branch - I don't think I'll be able to dive in any time soon sadly.

@sevaru
Copy link
Contributor

sevaru commented Feb 7, 2024

Thanks!

I've made a comment on the PR.

TL;DR:
Extending the class as your workaround is indeed the best approach for now!

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 a pull request may close this issue.

4 participants