Esm: Errors caught by @std/esm are expected to have a stack property of type string

Created on 27 Jan 2018  ·  2Comments  ·  Source: standard-things/esm

Consider the following index.js file run with node -r @std/esm index.js

process.on('uncaughtException', (e) => {
  try {
    // read e.stack
    const stack = e.stack
    console.log('work')
  } catch (err) {
    console.error(err)
  }
})
const err = new Error()
delete err.stack
throw err

@std/esm seem to expect anything that is instanceof Error to have a stack property of type string, so when the error thrown have no such property, @std/esm would throw an error Cannot read property 'replace' of undefined

Expected Output

which could be produced with simply node index.js

work

Actual Output

TypeError: Cannot read property 'replace' of undefined
    at MissingRefError.get (<cwd>/std-esm-repro-issue-259/node_modules/@std/esm/index.js:1:175661)
    at process._87a‍.r.process.on (<cwd>/std-esm-repro-issue-259/index.js:5:21)
    at process.emit (events.js:159:13)
    at process._fatalException (bootstrap_node.js:382:26)

I met this when using the package ajv, which would throw a MissingRefError who has Error.prototype in the prototype chain but doesn't have property stack.

Here's the repro repo: Mensu/std-esm-repro-issue-259

bug

All 2 comments

Ah nice find @Mensu!

Thank you!

v0.20.0 is released 🎉

Was this page helpful?
0 / 5 - 0 ratings