Skip to content

fix(next): don't log a phantom error for redirect()/notFound() signals#438

Merged
HugoRCD merged 2 commits into
mainfrom
fix/next-navigation-signal-phantom-error
Jul 22, 2026
Merged

fix(next): don't log a phantom error for redirect()/notFound() signals#438
HugoRCD merged 2 commits into
mainfrom
fix/next-navigation-signal-phantom-error

Conversation

@HugoRCD

@HugoRCD HugoRCD commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Closes #436

withEvlog treats Next.js control-flow signals thrown by redirect(), notFound(), forbidden(), and unauthorized() as real application errors: the catch block always called logger.error() and defaulted the status to 500 (these signals carry their real status in error.digest, not .status/.statusCode), leaving a phantom ERROR@500 wide event for every redirect/404.

Fix

Detect the signal before logging, using Next's own unstable_rethrow (from next/navigation) so it covers current and future signal types without hardcoding digest strings. If recognized, rethrow untouched — no logging, no emitted event. Otherwise, fall through to the existing error-logging path unchanged.

Testing

  • Added 3 regression tests in test/next/handler.test.ts: redirect() signal, notFound() signal, and a real error whose message happens to mention NEXT_REDIRECT (to confirm we only skip logging based on digest, not message content).
  • Full suite (pnpm run test), pnpm run lint, pnpm run typecheck, and pnpm run build:package all pass.
  • pnpm api:snapshot — no public API changes.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where Next.js control-flow helpers (redirect(), notFound(), and related responses) could be incorrectly recorded as HTTP 500 errors.
    • Navigation signal errors are now rethrown correctly, preventing phantom logging/output and avoiding draining for these non-error execution paths.
    • Improved handling when navigation signals are wrapped via error.cause, ensuring the underlying signal is rethrown without triggering error logging.
    • Genuine application errors still log normally, even if their message mentions Next.js redirect signals without the expected digest.

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, Comment, Open in v0 Jul 22, 2026 9:21am
just-use-evlog Ready Ready Preview, Comment Jul 22, 2026 9:21am

Request Review

@github-actions github-actions Bot added the bug Something isn't working label Jul 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: eb9db3f4-454d-413b-a808-d11f11b55b6f

📥 Commits

Reviewing files that changed from the base of the PR and between fd5eb78 and 9399154.

📒 Files selected for processing (2)
  • packages/evlog/src/next/handler.ts
  • packages/evlog/test/next/handler.test.ts

📝 Walkthrough

Walkthrough

withEvlog now detects Next.js navigation control-flow signals and rethrows them before error logging. Tests verify suppressed logging for valid signals and normal HTTP 500 handling for ordinary errors.

Changes

Next.js navigation signal handling

Layer / File(s) Summary
Detect and rethrow control-flow signals
packages/evlog/src/next/handler.ts
Dynamically checks for Next.js unstable_rethrow and invokes it before the wrapper’s normal error conversion and logging path.
Validate signal and error handling
packages/evlog/test/next/handler.test.ts, .changeset/fix-next-navigation-signal-phantom-error.md
Tests valid and wrapped navigation signals for identity preservation and suppressed logging, while confirming signal-like ordinary errors remain logged at status 500; documents the patch.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • HugoRCD/evlog#381: Both changes modify the Next.js handler’s error-processing path.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, conventional, and accurately summarizes the Next.js phantom error fix.
Description check ✅ Passed The description covers the issue, fix, and testing, though the checklist boxes are not filled in.
Linked Issues check ✅ Passed The change satisfies #436 by rethrowing Next.js control-flow signals without logging phantom ERROR@500 events.
Out of Scope Changes check ✅ Passed The added tests and changeset are directly related to the Next.js logging fix, with no unrelated code changes evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/next-navigation-signal-phantom-error

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 22, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/evlog@438
npm i https://pkg.pr.new/@evlog/nuxthub@438
npm i https://pkg.pr.new/@evlog/telemetry@438

commit: fd5eb78

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/evlog/src/next/handler.ts`:
- Around line 129-139: Update isNextNavigationSignal to separate the
next/navigation import failure from invoking unstable_rethrow, type
unstable_rethrow as returning void, and return false only when the import or
function availability check fails. Invoke unstable_rethrow outside the import
catch so its thrown unwrapped redirect/not-found signal propagates directly
instead of comparing thrown === error.

In `@packages/evlog/test/next/handler.test.ts`:
- Around line 134-188: Add tests alongside the existing redirect() and
notFound() cases for forbidden() and unauthorized() navigation signals, using
digests NEXT_HTTP_ERROR_FALLBACK;403 and NEXT_HTTP_ERROR_FALLBACK;401
respectively. For each handler, assert the original error is rethrown by
identity and that consoleErrorSpy, consoleSpy, and the drain mock are not
called.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2aa19683-f75e-4c71-bd4a-55bf5ba5ffaf

📥 Commits

Reviewing files that changed from the base of the PR and between 30ccb08 and fd5eb78.

📒 Files selected for processing (3)
  • .changeset/fix-next-navigation-signal-phantom-error.md
  • packages/evlog/src/next/handler.ts
  • packages/evlog/test/next/handler.test.ts

Comment thread packages/evlog/src/next/handler.ts Outdated
Comment thread packages/evlog/test/next/handler.test.ts
@HugoRCD
HugoRCD merged commit 51c5752 into main Jul 22, 2026
13 of 15 checks passed
@HugoRCD
HugoRCD deleted the fix/next-navigation-signal-phantom-error branch July 22, 2026 09:20
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

Successfully merging this pull request may close these issues.

withEvlog (Next.js) logs a phantom ERROR at status 500 for every redirect() / notFound()

1 participant