Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Error.cause not logged correctly #2446

Closed
lexctk opened this issue Apr 9, 2024 · 4 comments · Fixed by #2447
Closed

[Bug]: Error.cause not logged correctly #2446

lexctk opened this issue Apr 9, 2024 · 4 comments · Fixed by #2447

Comments

@lexctk
Copy link
Contributor

lexctk commented Apr 9, 2024

🔎 Search Terms

Error.cause, cause property

The problem

Error.cause is not logged correctly.
For reference. Error.cause was added to es2022.

This seems to have been fixed in logform @#winstonjs/logform#226, but not in winston.

What version of Winston presents the issue?

v3.13.0

What version of Node are you using?

v21.6.2

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

const log = winston.createLogger({
	format: format.combine(
		format.errors({ cause: true }),
		format.json(),
	),
	transports: [ new transports.Console() ],
});

log.error(new Error("I'm an error", { cause: new Error("with a cause") }));

// {"cause":{},"level":"error","message":"I'm an error"}

Additional information

No response

@lexctk
Copy link
Contributor Author

lexctk commented Apr 9, 2024

The current workaround is to pass cause as a string, which seems to work

log.error(new Error("I'm an error", { cause: "with a string cause" }));

// {"cause":"with a string cause","level":"error","message":"I'm an error"}

but defeats the purpose, eg, a more common use case:

try {
  connectToDatabase();
} catch (err) {
  throw new Error("Connecting to database failed.", { cause: err });
}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause

@jazanne
Copy link

jazanne commented Nov 1, 2024

this is honestly such a huge drag right now

@DABH DABH closed this as completed in #2447 Nov 1, 2024
@DABH
Copy link
Contributor

DABH commented Nov 1, 2024

This has been shipped in winston 3.16.0 🚀

@jazanne
Copy link

jazanne commented Nov 4, 2024

@DABH thank you!

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

Successfully merging a pull request may close this issue.

3 participants