You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
logError swallows error details (such as cause) #6462
Express configures finalhandler’s onError function in application.js:156 to call logError, which basically calls console.error(err.stack || err.toString()).
Some years ago logging err.stack was the only way to print out the error message and stack trace at once, as logging just err would miss some things (I don’t remember what). This has changed and nowadays it seems to be the other way round.
For example, there is now the Error.cause property allowing to specify a nested error. console.log(new Error("outer", { cause: new Error("inner") })) prints the nested error, while console.log(new Error("outer", { cause: new Error("inner") }).stack) misses it.
Async stack traces might be another example, although I couldn’t find a good way to test this.
In my concrete case, I am using Sequelize and an error occurred. Express basically logged the error as Error: with a stack trace that was not very helpful. After some investigation, I found out that logging the error object itself rather than its stack property reveals tons of information about the error that were otherwise missing. It seems that Sequelize errors contain nested errors in the parent and original properties, and those are logged as well when using console.error(error) but not with console.error(error.stack).
As a workaround, I am using this as the final middleware in my app:
Hi, I’d like to work on this issue.
My understanding is that logging err.stack hides modern error metadata like cause.
Would replacing it with console.error(err) be acceptable, or would you prefer a more backward-compatible approach?
aye @cdauth you are correct in that this is vestigial due to old node limitations of console.error from back in the day. console.error(err) did not log the stack back in the day, hence the explicit workaround
nvm exec 0.10 node -e "console.error(new Error('test'))"
[Error: test] # only the error message!
nvm exec 18 node -e "console.error(new Error('test'))"
Error: test # message plus stack in modern node
at [eval]:1:15
...
That exact logerror code is straight from the v3 => v4 migration of express and just hasnt been looked at since (it was inlined in the handle in v3, but v4 moved it to logerror). Ty for the report
Opened #7290 with the \console.error(err)\ fix (aligned with approved #6464) plus a regression test on current master. Happy to consolidate with #6464 if maintainers prefer one PR — main goal is getting the fix and test merged.
Activity
Nitin-Mohapatra commentedon Apr 17, 2025
I’m working on this. Will open a PR soon 😊
fix: log error cause chain in logerror function
fix: preserve error details like cause in logerror
LovekeshAnand commentedon Feb 11, 2026
Hi, I’d like to work on this issue.
My understanding is that logging err.stack hides modern error metadata like cause.
Would replacing it with console.error(err) be acceptable, or would you prefer a more backward-compatible approach?
krzysdz commentedon Feb 11, 2026
@LovekeshAnand there have been already some PRs, including #6464 which does exactly that and is waiting for reviews.
LovekeshAnand commentedon Feb 11, 2026
hey, thanks for replying.
i will look for another issue to contribute as a first time contributer
jonchurch commentedon Feb 12, 2026
aye @cdauth you are correct in that this is vestigial due to old node limitations of
console.errorfrom back in the day.console.error(err)did not log the stack back in the day, hence the explicit workaroundThat exact
logerrorcode is straight from the v3 => v4 migration of express and just hasnt been looked at since (it was inlined in the handle in v3, but v4 moved it tologerror). Ty for the reportFix expressjs#6462: log error object instead of err.stack to preserve…
fix: log full error object instead of just stack in logerror
fix: logerror now preserves Error.cause and custom properties
fix(application): preserve error details in logError
fix: log full error object in logerror to preserve error.cause
myselfsiddharth commentedon May 29, 2026
Opened #7290 with the \console.error(err)\ fix (aligned with approved #6464) plus a regression test on current master. Happy to consolidate with #6464 if maintainers prefer one PR — main goal is getting the fix and test merged.
fix: log full error object in logerror to preserve cause
fix: log full error object in logerror to preserve cause