Skip to content

fix(nitro): skip default logging for expected evlog 4xx errors - #819

Merged
HugoRCD merged 2 commits into
mainfrom
EVL-534/nitro-skip-default-log-expected-errors
Oct 10, 2026
Merged

HugoRCD merged 2 commits into
mainfrom
EVL-534/nitro-skip-default-log-expected-errors

Conversation

@evlogai

@evlogai evlogai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Refs EVL-534. Closes #814.

Change

evlog's Nitro error handlers (src/nitro/errorHandler.ts for v2, src/nitro-v3/errorHandler.ts for v3) call Nitro's ctx.defaultHandler whenever the dev overlay is not suppressed. In production that is always the case, so Nitro printed every thrown createError as [request error] [unhandled] with a stack dump, on top of the wide event evlog already writes.

The handlers now skip defaultHandler when the error is an EvlogError with a status below 500. The check lives in a new isExpectedEvlogError helper in src/nitro.ts. 5xx EvlogErrors and non-evlog errors are still logged by Nitro.

Behavior change to review

The skip applies whatever the dev preset, so dev: 'nitro' or 'both' no longer shows Nitro's overlay for expected 4xx EvlogErrors either. Those errors are still in the wide event. If you want the overlay kept in dev, the check can be scoped to non-dev.

Evidence

Unit tests

Regression test written first, run on main before the fix (test/nitro/errorHandler.test.ts, same case in test/nitro-v3/errorHandler.test.ts):

FAIL  skips Nitro default logging for an expected 4xx EvlogError in production
AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times
  [EvlogError: Payment failed], { _handled: true, ... }, { silent: false }

After the fix: both files pass, 45 tests. The 5xx case passes before and after.

End to end (Nitro v2, production build)

Run in apps/nitro-v2-playground with NODE_ENV=production nitropack build and node .output/server/index.mjs, then GET /api/test/error, which throws createError({ status: 400, why, fix, link }).

On main (038de6a):

HTTP 400
{"url":"/api/test/error","status":400,...,"data":{"why":"Card declined by issuer","fix":"Try a different payment method","link":"https://docs.example.com/payments/declined"}}

[request error] [unhandled] [GET] http://localhost:3132/api/test/error
 EvlogError: Payment processing failed
    at createError (...)
  statusCode: 400,
  fatal: false,
  unhandled: true,
  ...

On this branch (3d3387e), same request:

HTTP 400
{"url":"/api/test/error","status":400,...,"data":{"why":"Card declined by issuer","fix":"Try a different payment method","link":"https://docs.example.com/payments/declined"}}

No [request error] line. The response body is identical in both runs.

5xx check on this branch, using a temporary route that throws createError({ status: 503 }) (removed afterward): Nitro still prints [request error] [unhandled] with the stack, and the wide event is still written with statusCode: 503.

The playground prints [evlog] ... called after the wide event was emitted warnings in both runs. They come from the playground route and are unrelated to this change.

Checks

  • pnpm run lint: pass
  • pnpm run typecheck: pass (after dev:prepare for apps/telemetry; the first run failed there only because its .nuxt directory was missing)
  • pnpm --filter evlog exec vitest run: 100 of 100 test files pass
  • Nitro suites: 125 tests pass after pnpm --filter evlog build

Not verified

  • The reproduction uses Nitro v2 through apps/nitro-v2-playground, not a full Nuxt app. The Nitro v3 handler is covered by unit tests only.
ELI5

When a request fails for an expected reason, such as a declined card, evlog already writes one clear log line. Nitro, the server under Nuxt, was also printing a long "unhandled error" block for it. This change stops Nitro from printing that block for expected 4xx errors. Real server failures are still printed.

@evlogai
evlogai Bot requested a review from HugoRCD October 10, 2026 18:49
@vercel

vercel Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
evi Ready Ready Preview Oct 10, 2026 6:51pm UTC
evlog-docs Ready Ready Preview, v0 Oct 10, 2026 6:51pm UTC
evlog-render-lab Ready Ready Preview Oct 10, 2026 6:51pm UTC
evlog-telemetry Ready Ready Preview Oct 10, 2026 6:51pm UTC
just-use-evlog Ready Ready Preview Oct 10, 2026 6:51pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 317876bd-179e-4b29-93d4-05cbd91d77cc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@pkg-pr-new

pkg-pr-new Bot commented Oct 10, 2026

Copy link
Copy Markdown
@evlog/cli

npm i https://pkg.pr.new/@evlog/cli@819

evlog

npm i https://pkg.pr.new/evlog@819

@evlog/nuxthub

npm i https://pkg.pr.new/@evlog/nuxthub@819

@evlog/signals

npm i https://pkg.pr.new/@evlog/signals@819

@evlog/telemetry

npm i https://pkg.pr.new/@evlog/telemetry@819

commit: 3d3387e

@HugoRCD
HugoRCD merged commit e7c954b into main Oct 10, 2026
22 checks passed
@HugoRCD
HugoRCD deleted the EVL-534/nitro-skip-default-log-expected-errors branch October 10, 2026 22:02

This branch was successfully deployed

5 active deployments
Preview – evlog-telemetry — 3d3387e3 Deployed Oct 10, 2026 by vercel[bot]
Preview – evi — 3d3387e3 Deployed Oct 10, 2026 by vercel[bot]
Preview – evlog-docs — 3d3387e3 Deployed Oct 10, 2026 by vercel[bot]
Preview – evlog-render-lab — 3d3387e3 Deployed Oct 10, 2026 by vercel[bot]
Preview – just-use-evlog — 3d3387e3 Deployed Oct 10, 2026 by vercel[bot]
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.

Nitro prints evlog createError 4xx as [unhandled] in production

1 participant