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

Error's cause not respected (for non-Error causes) #9913

Closed
3 tasks done
jeengbe opened this issue Dec 19, 2023 · 6 comments · Fixed by #9914
Closed
3 tasks done

Error's cause not respected (for non-Error causes) #9913

jeengbe opened this issue Dec 19, 2023 · 6 comments · Fixed by #9914
Labels
Package: browser Issues related to the Sentry Browser SDK Type: Bug

Comments

@jeengbe
Copy link
Contributor

jeengbe commented Dec 19, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

7.88.0

Framework Version

n/a

Link to Sentry event

https://prisjakt-ab.sentry.io/issues/4738454694/events/latest/?project=4506415694348288

SDK Setup

Sentry.init({
  // ...
  integrations: [
    new Sentry.Integrations.Http(),
    new Sentry.Integrations.FunctionToString(),
    new Sentry.Integrations.ContextLines(),
    new Sentry.Integrations.LocalVariables(),
    new Sentry.Integrations.LinkedErrors(),
    new Sentry.Integrations.RequestData({
      include: {
        user: false,
        ip: true,
        cookies: false,
        data: false,
        headers: false,
        query_string: false,
        url: false,
      },
    }),
  ],
  // ...
});
Sentry.withScope((scope) => {
  scope.setSDKProcessingMetadata({ request: ctx.request });
  Sentry.captureException(error);
});

Steps to Reproduce

  1. Do API request:
try {
  const res = await doFetch();

  if (res.error) {
    throw new Error("Request failed", {
      cause: res
    });
  }
  1. Catch error and log it
} catch (err) {
  Sentry.withScope((scope) => {
    scope.setSDKProcessingMetadata({ request: ctx.request });
    Sentry.captureException(err);
  });
}

This adds the failed API response as cause on the error object. Yet on the linked issue in Sentry, there is no reference to that error cause.

Expected Result

The cause should somehow show in Sentry. I saw it do that for Error-causes. I saw some other GH issue thread that had something to do with a React boundary, but that was fixed and closed, so likely not applicable (also I can't find the link any more)

Actual Result

The cause doesn't show on the Sentry issue.

@jeengbe jeengbe changed the title Error cause not respected (for non-Error casuses) Error cause not respected (for non-Error causes) Dec 19, 2023
@github-actions github-actions bot added the Package: browser Issues related to the Sentry Browser SDK label Dec 19, 2023
@jeengbe jeengbe changed the title Error cause not respected (for non-Error causes) Error's cause not respected (for non-Error causes) Dec 19, 2023
@lforst
Copy link
Member

lforst commented Dec 19, 2023

Hi, linking errors based on the cause property with the LinkedErrors integration is only supported if the value behind cause is an Error. What you likely need and want is the ExtraErrorData integration. Let me know if this helps!

@jeengbe
Copy link
Contributor Author

jeengbe commented Dec 19, 2023

Ah so when I see an issue in Sentry with another linked issue, that's a linked Sentry issue that's linked from the cause?

@lforst
Copy link
Member

lforst commented Dec 19, 2023

Ah so when I see an issue in Sentry with another linked issue, that's a linked Sentry issue that's linked from the cause?

I don't think it's an "issue" but definitely another error object on the cause property of the captured error.

@jeengbe
Copy link
Contributor Author

jeengbe commented Dec 19, 2023

Is that something you would consider supporting? Structured non-Error data is explicitly allowed according to MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause#providing_structured_data_as_the_error_cause

@lforst
Copy link
Member

lforst commented Dec 19, 2023

We definitely could! Putting on backlog.

@lforst
Copy link
Member

lforst commented Dec 19, 2023

Figured this is so easy to do I'll just open a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: browser Issues related to the Sentry Browser SDK Type: Bug
Projects
None yet
2 participants