tc39 / tc39/proposal-error-code-property

Conflict on Enumerable: false

Open
#9 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
38
Forks
1
PR merge metrics
No merged PRs in 30d

Description

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) // '{}'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start with the current and proposed JSON.stringify(), for...in, Object.keys(), Object.values(), and Object.entries() examples in the issue, then review the compatibility concern and define an agreed resolution for the property's enumerability; done requires a documented proposal decision.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.