Skip to content

fix(application): preserve error details in logError#7118

Closed
wdskuki wants to merge 1 commit into
expressjs:masterfrom
wdskuki:fix/logerror-preserve-error-details
Closed

fix(application): preserve error details in logError#7118
wdskuki wants to merge 1 commit into
expressjs:masterfrom
wdskuki:fix/logerror-preserve-error-details

Conversation

@wdskuki
Copy link
Copy Markdown

@wdskuki wdskuki commented Mar 21, 2026

Problem

The current logError implementation uses err.stack || err.toString(), which loses important error details:

  • Error.cause chain (introduced in ES2022)
  • Asynchronous stack traces (from async/await)
  • Custom error properties
  • Error metadata added by libraries

Solution

Change console.error(err.stack || err.toString()) to console.error(err) to preserve the full error object, allowing Node.js to format it completely.

Changes

  • Modified lib/application.js to pass the error object directly to console.error

Testing

  • Verified that passing the error object directly preserves all error details
  • The change is backward compatible as console.error handles Error objects correctly

Fixes potential issues where error context is lost during logging.

Change console.error(err.stack || err.toString()) to console.error(err)
to preserve error details like Error.cause, async stack traces, and
custom error properties that are lost when only logging err.stack.

Fixes expressjs#6462
@krzysdz
Copy link
Copy Markdown
Contributor

krzysdz commented Mar 21, 2026

Duplicate of #6464

@krzysdz krzysdz marked this as a duplicate of #6464 Mar 21, 2026
@krzysdz krzysdz closed this Mar 21, 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.

2 participants