Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

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

Closed
Mensu opened this issue Jan 27, 2018 · 2 comments
Closed
Labels

Comments

@Mensu
Copy link

Mensu commented Jan 27, 2018

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

@jdalton
Copy link
Member

jdalton commented Jan 27, 2018

Ah nice find @Mensu!

Thank you!

@jdalton jdalton added the bug label Jan 27, 2018
@jdalton
Copy link
Member

jdalton commented Jan 28, 2018

v0.20.0 is released 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants