Closed
Description
Guidelines
- Please search other issues to make sure this bug has not already been reported.
- If this is related to a typo or the documentation being unclear, please click on the relevant page's
Edit
button (pencil icon) and suggest a correction instead.
Describe the bug
When I try to print an instance of ModernError's subClass, I find that the message
passed to the constructor when creating the instance will be printed twice, whereas an instance of Error created with new Error()
does not print the message
twice. And for some reason, I'm not considering using winston-error-format
for now.
Steps to reproduce
Run such a script ( use "node index.js"):
// index.js
import ModernError from "modern-errors";
import stack from "modern-errors-clean";
let myError = ModernError.subclass("MyError", { plugins: [stack] });
try {
throw new myError("a error", {
cause: {"aaa": 1},
errors: [new myError("error1"), new myError("error2")]
})
} catch (e) {
console.log("e: ")
console.log(e)
console.log("message: ")
console.log(e.message)
console.log("stack:")
console.log(e.stack)
}
the error message ("a error") will be printed twice, which is out of my expection:
e:
MyError: {"aaa":1}
a error
a error
at file:///index.js:7:11 {
[errors]: [
MyError: error1
at file:///index.js:9:18,
MyError: error2
at file:///index.js:9:41
]
}
message:
{"aaa":1}
a error
a error
stack:
MyError: {"aaa":1}
a error
a error
at file:///index.js:7:11
Configuration
Environment
node -v
v22.13.0
ver
Microsoft Windows [Version 10.0.19045.5487]
Pull request (optional)
- I can submit a pull request.