Skip to content

Conversation

OP-Prajwal
Copy link

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 cause work 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

- Add support for logging Error.cause property
- Recursively log entire cause chain with 'Caused by:' prefix
- Maintains backward compatibility with errors without cause
- Fixes expressjs#6462
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