getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.97k stars 1.57k forks source link

There are some types of exceptions that can't be caught by `@sentry/nextjs` #3543

Closed redshoga closed 1 year ago

redshoga commented 3 years ago

Package + Version

Version:

"@sentry/nextjs": "^6.3.6",
"next": "^10.0.8",

Description

Exceptions that do not jump to an error page, such as the following, can be correctly detected by Sentry.

import React from 'react';

const Sample: React.FC = () => {
  return (
    <button
      onClick={() => {
        throw new Error('Sentry Frontend Error! in useEffect');
      }}
    >
      Throw error
    </button>
  );
};

export default Sample;

However, Sentry will not detect exceptions that redirect to error pages, such as the following, if you only set @sentry/nextjs.

import React, { useEffect } from 'react';

const Sample: React.FC = () => {
  useEffect(() => {
    throw new Error('Sentry Frontend Error! in useEffect');
  }, []);

  return (
    <button
      onClick={() => {
        // throw new Error('Sentry Frontend Error! in useEffect');
      }}
    >
      Throw error
    </button>
  );
};

export default Sample;

Does the developer need to include code on the _error page to notify Sentry, as in the following sample?

https://github.com/vercel/next.js/blob/canary/examples/with-sentry/pages/_error.js

myyellowshoe commented 3 years ago

Noticing the same issue here.

NoobTW commented 3 years ago

Same here.

Adding custom _error.js is a workaround for me.

iker-barriocanal commented 3 years ago

Related to https://github.com/getsentry/sentry-javascript/issues/3869, https://github.com/getsentry/sentry-javascript/issues/3901, https://github.com/getsentry/sentry-javascript/issues/3970 and https://github.com/getsentry/sentry-javascript/issues/3970.

timfish commented 1 year ago

This issue is over a year old.

Is this still reproducible in the latest version of the SDK? If so, does this answer how to overcome this?

smeubank commented 1 year ago

closing issue for now, since there are a number of at least seemingly related issue we have in the backlog as well. We can re-open if needed