caolan / async

Async utilities for node and the browser
http://caolan.github.io/async/
MIT License
28.18k stars 2.41k forks source link

reflect does not use Error message #1873

Closed Fr33maan closed 1 year ago

Fr33maan commented 2 years ago

What version of async are you using? 3.2.0

Which environment did the issue occur in (Node/browser/Babel/Typescript version)

{
    "async": "^3.2.0",
    "typescript": "4.5.4",
    "jest": "^27.5.1",
    "babel-jest": "^27.5.1",
    "babel-loader": "^8.1.0"
}

What did you do? Please include a minimal reproducible case illustrating issue.

  test.only('test reflect', async () => {
    const testFn = async () => { throw { message: 'test error' } }
    const result = await parallel([reflect(testFn)])
    console.log("result: %s", JSON.stringify(result, null, 4))

    const testFn2 = async () => { throw new Error('test error') }
    const result2 = await parallel([reflect(testFn2)])
    console.log("result2: %s", JSON.stringify(result2, null, 4))
  })

What did you expect to happen? Second call should return the error message or the Error itself in the error property and not hide the Error

What was the actual result?

    console.log
      result: [
          {
              "error": {
                  "message": "test error"
              }
          }
      ]

    console.log
      result2: [
          {
              "error": {}
          }
      ]
aearly commented 1 year ago

Expected behavior due to how JSON.stringify(new Error('hello')) works.