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

Mistake in Sentry documentation #2263

Open
edhgoose opened this issue Aug 14, 2024 · 1 comment
Open

Mistake in Sentry documentation #2263

edhgoose opened this issue Aug 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@edhgoose
Copy link

Please list the package(s) involved in the issue, and include the version you are using

checkout-ui-extensions

Describe the bug

In the documentation for Sentry: https://shopify.dev/docs/api/checkout-ui-extensions/unstable/error-handling#sentry, the following code snippet is defined:

self.addEventListener('error', (error) => {
  Sentry.captureException(
    new Error(error.reason.stack),
  );
});

But, as per typescript, reason doesn't exist on error:

CleanShot 2024-08-14 at 09 25 39@2x

Neither does it say so on MDN: https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent

This suggests that either the type is wrong (perhaps I've got the wrong ErrorEvent somehow?) or that the documentation is wrong.

Given the documentation above it does have an error.reason, I'm led to believe this is a copy paste mistake from above.

Steps to reproduce the behavior:

  1. Add the code from the link above into your project.
  2. Confirm that Typescript complains about an error.

Expected behavior

Correct documentation on how to capture error messages, and a recommendation on how to ensure that the right stack trace is captured.

I think this is right?

self.addEventListener('error', (error) => {
    let err = error.error;

    if ( ! (err instanceof Error)) {
        err = new Error(error.message);
    }
   
    Sentry.captureException(err);
});

Screenshots

Additional context

I'm raising this issue because we're finding we're getting unexpected errors. The errors don't have an obvious stack trace so they're very difficult to diagnose.

#2198 would be hugely beneficial too.

@edhgoose edhgoose added the bug Something isn't working label Aug 14, 2024
@edhgoose
Copy link
Author

As requested in #2521, I have re-raised this issue as: https://community.shopify.dev/t/bug-mistake-in-sentry-documentation/6395

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant