Skip to content

fix: log full error object in logerror (fixes #6462)#7290

Open
myselfsiddharth wants to merge 1 commit into
expressjs:masterfrom
myselfsiddharth:fix/logerror-full-error-object-6462
Open

fix: log full error object in logerror (fixes #6462)#7290
myselfsiddharth wants to merge 1 commit into
expressjs:masterfrom
myselfsiddharth:fix/logerror-full-error-object-6462

Conversation

@myselfsiddharth
Copy link
Copy Markdown

Summary

Changes logerror in lib/application.js to use console.error(err) instead of console.error(err.stack || err.toString()), so Node's built-in error inspection preserves Error.cause, custom enumerable properties (e.g. Sequelize parent/original), and AggregateError details.

This matches the approach in #6464 (approved in review; vestigial err.stack workaround from pre-Node-18 when console.error(err) did not print stacks). Express 5 already requires Node >= 18.

This PR is rebased on current master and adds regression test coverage (test/app.logerror.js) for the default error handler logging path.

Fixes #6462

Related PRs

Test plan

  • npm test -- test/app.logerror.js
  • Full suite: npm test (1250 passing)

Behavior note

Only affects stderr when the default error handler runs and env !== 'test'. HTTP responses are unchanged.

Use console.error(err) instead of err.stack || err.toString() so Node's built-in error inspection includes Error.cause, custom properties (e.g. Sequelize parent/original), and AggregateError details.

Adds regression test for the default error handler logging path.

Fixes expressjs#6462

Related: expressjs#6464 (same one-line fix; this PR adds test coverage and is rebased on current master)
Co-authored-by: Cursor <cursoragent@cursor.com>
@myselfsiddharth
Copy link
Copy Markdown
Author

cc @Nitin-Mohapatra — happy to help rebase #6464 or fold this test into that PR if maintainers prefer a single PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logError swallows error details (such as cause)

1 participant