Skip to content

Log error objects in the default error handler#7288

Closed
Subharup-31 wants to merge 1 commit into
expressjs:masterfrom
Subharup-31:fix/log-error-object-details
Closed

Log error objects in the default error handler#7288
Subharup-31 wants to merge 1 commit into
expressjs:masterfrom
Subharup-31:fix/log-error-object-details

Conversation

@Subharup-31
Copy link
Copy Markdown

@Subharup-31 Subharup-31 commented May 29, 2026

Problem

The default Express final-handler logger currently logs err.stack || err.toString(). That stringifies the error too early and can hide structured error details such as Error.cause or additional properties provided by libraries.

Root cause

logerror extracts the stack string before passing the error to console.error, so Node's object/error formatter cannot include nested details.

Fix

Pass the error object directly to console.error. This preserves existing stack output while allowing runtimes to include richer error object information.

Testing

  • Added a regression test that verifies the default logger receives the original error object.
  • Ran git diff --check successfully.

Fixes #6462

@krzysdz
Copy link
Copy Markdown
Contributor

krzysdz commented May 29, 2026

Duplicate of #6464

@krzysdz krzysdz marked this as a duplicate of #6464 May 29, 2026
@krzysdz krzysdz closed this May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logError swallows error details (such as cause)

2 participants