8000 When attempting to print an error, the "message" will be printed twice · Issue #33 · ehmicky/modern-errors · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
When attempting to print an error, the "message" will be printed twice #33
Closed
@heyhey123-git

Description

@heyhey123-git

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 messagetwice. 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]
// package.json
"dependencies": {
    "modern-errors": "^7.0.1",
    "modern-errors-clean": "^6.0.0"
}

Pull request (optional)

  • I can submit a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0