fix: log error cause chain in logerror function
Fixes #6462
Problem
The logerror function in Express was only logging err.stack, which doesn't display the error cause property introduced in Node.js 16.9.0. This meant that error chains were not visible in logs, making debugging more difficult.
Solution
Modified the logerror() function to explicitly log the complete error cause chain. When an error has a cause, it now logs each error in the chain with a "Caused by:" prefix for clarity.
Changes
- Updated
lib/application.js-logerror()function now iterates through the error cause chain - Maintains backward compatibility - errors without
causework exactly as before - All existing tests pass (1236 passing)
Before
Error: Failed to fetch user data
at ...
After
Error: Failed to fetch user data
at ...
Caused by: Error: Failed to execute query
at ...
Caused by: Error: Database connection timeout
at ...
Testing
- All existing tests pass (1236 passing)
- Tested with error chains using Node.js Error.cause
- Backward compatible with errors without cause
- Requires Node.js 16.9.0+ for Error.cause support
Thanks for your contribution!
Noticed that #6464 also solves the same issue, would it make sense to collaborate there instead of having two fixes? That way, the maintainers would review only a single fix.
Thanks for your contribution!
Noticed that #6464 also solves the same issue, would it make sense to collaborate there instead of having two fixes? That way, the maintainers would review only a single fix.
Thanks for your contribution!
Noticed that #6464 also solves the same issue, would it make sense to collaborate there instead of having two fixes? That way, the maintainers would review only a single fix.
According to me Printing an entire error object is somewhat unnecessary because it will be too big and confusing for people to debug the issue. I would prefer to print only the cause as I did in my pr. Hope u get the actual point
According to me Printing an entire error object is somewhat unnecessary because it will be too big and confusing for people to debug the issue. I would prefer to print only the cause as I did in my pr. Hope u get the actual point
How exactly printing all .stack properties of error and its causes results in less text than logging full error (which does exactly the same thing, but can also automatically indent nested errors/objects)? Using just console.error(err) like in #6464 helps with AggregateErrors too.