fix: preserve full error details in logerror (Error.cause, nested errors)#7313
Closed
armorbreak001 wants to merge 1 commit into
Closed
fix: preserve full error details in logerror (Error.cause, nested errors)#7313armorbreak001 wants to merge 1 commit into
armorbreak001 wants to merge 1 commit into
Conversation
console.error(err.stack || err.toString()) strips important error properties like Error.cause, custom properties added by libraries (e.g. Sequelize's parent/original), and async stack trace context. Changing to console.error(err) preserves the complete error object output while still showing stack traces. This matches modern Node.js behavior where console.error handles Error objects comprehensively. Fixes expressjs#6462
Contributor
|
Duplicate of #6464 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
logerror()currently logserr.stack || err.toString(). This strips important error information:Error.cause(ES2022) — nested/wrapped errors are invisible in logsparent,original, and other diagnostic properties that get lostReal-world impact
When using Sequelize (or any library that wraps errors), Express currently logs just
Error:with an unhelpful stack trace. The actual database error details (constraint violation, connection failure reason, etc.) are hidden inside properties thaterr.stackdoes not include.Solution
One-line change:
console.error(err.stack || err.toString())→console.error(err)This preserves the complete error object output while still showing stack traces. Node's
console.errorhandles Error objects comprehensively — it prints the message, cause chain, custom properties, and stack.Before
(No indication of what actually went wrong)
After
Testing
console.error(new Error("outer", { cause: new Error("inner") }))now shows both errorsBackwards Compatibility
Fully backwards compatible. The output is strictly more informative — no information is removed, only added.
Fixes #6462