If Enumerable is false:
- It will break current behavior of
JSON.stringify(), for ... in, Object.keys(), Object.values(), and Object.entries() on errors with "manualy" set code properties.
- It will limit one of the key advantage (in my opinion) of this code property as it won't be propagated in logs by default (the error message only is propagated because developers painfuly learned to extract it manually instead of relying on default JSON stringify behavior)
We may have a look on how the code property is used in the mentioned libraries, but it is impossible to know how it is used by those library consumers worlwide, not even talking about application level defined code properties
Even if the purpose is good, I do think it is very ambitious to try add constraints on a such commonly used Error property name and probably incompatible with the W3C mantra "Don't break the Web", maybe another property name would be more appropriate
Conflict
Current behavior
const err = new Error('foo')
err.code = 'ERR_FOO'
// or const err = Object.assign(new Error('foo'), { code: 'ERR_FOO' })
JSON.stringify(err) // '{"code":"ERR_FOO"}'
Behavior with Enumerable false
const err = new Error('foo')
Object.defineProperty(err, 'code', { value: 'ERR_FOO', enumerable: false })
JSON.stringify(err) // '{}'
If Enumerable is false:
JSON.stringify(),for ... in,Object.keys(),Object.values(), andObject.entries()on errors with "manualy" setcodeproperties.We may have a look on how the code property is used in the mentioned libraries, but it is impossible to know how it is used by those library consumers worlwide, not even talking about application level defined code properties
Even if the purpose is good, I do think it is very ambitious to try add constraints on a such commonly used Error property name and probably incompatible with the W3C mantra "Don't break the Web", maybe another property name would be more appropriate
Conflict
Current behavior
Behavior with Enumerable false