JS-DevTools / ono

Wrap errors without losing the original message, stack trace, or properties
https://jstools.dev/ono/
MIT License
106 stars 11 forks source link

Symbol prop keys are not working #8

Closed adipascu closed 5 years ago

adipascu commented 5 years ago

Thank you for the great library! I have a usecase with symbols that is not currently working, here is some sample code:

const ono = require('ono');

const SOME_PROP = Symbol('symbol-name');
// const SOME_PROP = 'string-key'; // (string keys work correctly)
function fun() {
  try {
    throw new Error('original error');
  } catch (e) {
    throw ono(e, { [SOME_PROP]: true }, 'wrapped with [SOME_PROP]');
  }
}

try {
  fun();
} catch (e) {
  console.log(`Has prop: ${e[SOME_PROP] || false}`);
}
JamesMessinger commented 5 years ago

Good catch! I never even thought about supporting symbol props, but that totally makes sense.

JamesMessinger commented 5 years ago

We just released Ono v5.0, which fixes this issue. Thanks for reporting it!

Here are the release notes