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

NEXT_REDIRECT error to be reported as an Unhandled Error in Server Action redirect function. #14436

Closed
3 tasks done
NEKOYASAN opened this issue Nov 22, 2024 · 6 comments · Fixed by #14440
Closed
3 tasks done
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@NEKOYASAN
Copy link
Contributor

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

8.40.0

Framework Version

React 19.0.0-rc-66855b96-20241106 & Next.js 15.0.3

Link to Sentry event

https://nekoyasan.sentry.io/issues/6082760807/events/a7a626e05026406bb3d13a68e8270c92/

Reproduction Example/SDK Setup

Reproduction Example: https://github.com/NEKOYASAN/next-sentry-redirect-minimum-repro

Reproduction Steps (From completely empty)

  1. pnpm create next-app
  2. npx @sentry/wizard@latest -i nextjs --saas
  3. add Server Action & Components (redirect function in Server Action)

Steps to Reproduce

  1. pnpm run build
  2. pnpm run start
  3. Click Redirect to example page Button
  4. Redirects normally to /example (but NEXT_REDIRECT Error is reported to Sentry)

Expected Result

Maybe NEXT_REDIRECT should not be reported to Sentry.

Actual Result

Server Action reports NEXT_REDIRECT as Unhandled Error.

but it does not seem to be reported in page.tsx, so there seems to be no problem.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Nov 22, 2024
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Nov 22, 2024
@NEKOYASAN
Copy link
Contributor Author

NEKOYASAN commented Nov 22, 2024

Maybe ref: #7641 and #10038

@Zinnavoy
Copy link

Maybe ref: #7641 and #10038

Definitely ref, but funny enough it is still happening. +1

@NEKOYASAN
Copy link
Contributor Author

One way to prevent reporting is to add beforeSend to sentry.client.config.ts

Sentry.init({
  /* etc... */
  beforeSend(event, hint) {
    const error = hint.originalException as Error & { digest?: unknown };
    if (
      error &&
      error.digest &&
      typeof error.digest === 'string' &&
      error.digest.startsWith('NEXT_REDIRECT;')
    ) {
      return null;
    }
    return event;
  },
  /* etc... */
});

@NEKOYASAN
Copy link
Contributor Author

NEXT_REDIRECT should have been absorbed by the client-side redirect error boundary, but was somehow reported to Sentry as an Unhandled Error.

I don't remember seeing it on Next.js 15-rc0 + sentry/nextjs 8.27.0 , so maybe something changed between Next.js rc1,2 ~ 15.0.3

@Zinnavoy
Copy link

One way to prevent reporting is to add beforeSend to sentry.client.config.ts

Sentry.init({
/* etc... /
beforeSend(event, hint) {
const error = hint.originalException as Error & { digest?: unknown };
if (
error &&
error.digest &&
typeof error.digest === 'string' &&
error.digest.startsWith('NEXT_REDIRECT;')
) {
return null;
}
return event;
},
/
etc... */
});

This did the trick for me, thank you.

Copy link
Contributor

A PR closing this issue has just been released 🚀

This issue was referenced by PR #14440, which was included in the 8.41.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants