Skip to content

fix: ensure consistent error data serialization in production#29

Merged
HugoRCD merged 11 commits intomainfrom
fix/create-error
Feb 3, 2026
Merged

fix: ensure consistent error data serialization in production#29
HugoRCD merged 11 commits intomainfrom
fix/create-error

Conversation

@HugoRCD
Copy link
Copy Markdown
Owner

@HugoRCD HugoRCD commented Feb 2, 2026

Resolves #24

This pull request updates the EvlogError class and related utilities to improve compatibility across different versions of Nitro/H3, enhance structured error data, and modernize the API.
The main changes introduce new status and message properties, deprecate legacy ones, and ensure consistent error serialization and parsing.

@HugoRCD HugoRCD self-assigned this Feb 2, 2026
@HugoRCD HugoRCD requested a review from Copilot February 2, 2026 12:55
@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 2, 2026

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

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, Comment Feb 3, 2026 6:04pm

@github-actions github-actions Bot added the bug Something isn't working label Feb 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 2, 2026

Thank you for following the naming conventions! 🙏

@HugoRCD HugoRCD changed the title fix: createError data lost in production fix: createError data lost in production Feb 2, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 2, 2026

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

commit: f7bc4ff

@HugoRCD
Copy link
Copy Markdown
Owner Author

HugoRCD commented Feb 2, 2026

@NicolaSpadari, can you try to see if this version fixes the problem "evlog": "https://pkg.pr.new/evlog@29" ?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves EvlogError serialization/shape to preserve structured error data across Nitro/H3 versions (v2/v1 vs v3/v2), addressing production cases where custom error data was being dropped.

Changes:

  • Add Nitro v3+/H3 v2+ compatible fields (status, statusText) while keeping legacy (statusCode, statusMessage) as deprecated.
  • Move structured error context (why/fix/link) into a dedicated data object for consistent serialization.
  • Update parseError and tests to recognize both Nitro/H3 generations’ status/message fields.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/evlog/src/error.ts Extends EvlogError with status/statusText + legacy fields and serializes structured context under data.
packages/evlog/src/runtime/utils/parseError.ts Parses both Nitro v3+/v2 error response shapes for status and message fields.
packages/evlog/test/error.test.ts Updates/extends tests to cover the new status fields and the new JSON shape (data).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/evlog/src/error.ts Outdated
Comment thread packages/evlog/src/runtime/utils/parseError.ts Outdated
@NicolaSpadari
Copy link
Copy Markdown

NicolaSpadari commented Feb 2, 2026

Thank you for the quick check. Unfortunately, still seems to occur, and the "why" key gets lost after build.

I created a reproduction here https://github.com/NicolaSpadari/evlog-data-reproduction

Just try to run it as dev, click the button, see the network response.
Then build it and preview it, try again to click button and see the network response

"message" still comes through, "why" doesn't

@HugoRCD
Copy link
Copy Markdown
Owner Author

HugoRCD commented Feb 3, 2026

@NicolaSpadari And this time? with https://pkg.pr.new/evlog@116c96f

@NicolaSpadari
Copy link
Copy Markdown

Yes, looks like it's working!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/evlog/src/nitro/errorHandler.ts Outdated
Comment thread packages/evlog/src/nitro/errorHandler.ts Outdated
Comment thread packages/evlog/src/nuxt/module.ts Outdated
Comment thread packages/evlog/src/nitro/errorHandler.ts Outdated
@HugoRCD HugoRCD changed the title fix: createError data lost in production fix: ensure consistent error data serialization in production Feb 3, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/evlog/src/nitro/errorHandler.ts Outdated
Comment thread packages/evlog/src/nitro/errorHandler.ts Outdated
Comment thread packages/evlog/src/nitro/errorHandler.ts
Comment thread packages/evlog/src/runtime/utils/parseError.ts Outdated
Comment thread packages/evlog/src/runtime/utils/parseError.ts Outdated
Comment thread packages/evlog/src/error.ts Outdated
Comment thread packages/evlog/test/error.test.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/evlog/src/nitro/errorHandler.ts Outdated
Comment on lines +39 to +43
url,
statusCode: status,
statusMessage: message,
message,
error: true,
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The serialized response body only includes legacy statusCode/statusMessage. Since this PR introduces status/statusText for newer Nitro/H3/Nuxt versions, consider including status and statusText alongside the legacy fields in the JSON payload to make the on-the-wire format consistent and forward-compatible (without breaking existing consumers).

Copilot uses AI. Check for mistakes.
Comment thread packages/evlog/src/nitro/errorHandler.ts
Comment thread packages/evlog/src/error.ts
- Cache `this.data` in toJSON() to avoid calling getter twice
- Derive message from statusText/statusMessage/message for cross-version compat
- Add status/statusText fields to JSON response for Nuxt 4+ compatibility

Co-authored-by: Cursor <cursoragent@cursor.com>
@HugoRCD HugoRCD merged commit 18c386c into main Feb 3, 2026
9 of 10 checks passed
@HugoRCD HugoRCD deleted the fix/create-error branch February 3, 2026 18:04
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.

[bug] createEvlogError throws unhandled error in production

3 participants