镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Readonly error.code has ecosystem impact. #15658

Description

@jdalton

I know internal/errors usage is picking up in Node core so I thought I'd give a heads up on something I've seen in the wild. It looks like folks are adding error.code properties which will error with the internal/errors since error.code is readonly.

Is being readonly intentional?

Activity

  1. targos commented on Sep 28, 2017

    @targos
    Member

    There was some discussion about that in the PR introducing internal/errors: #11220 (review)

    /cc @jasnell

  2. added
    errorsIssues and PRs related to JavaScript errors originating in Node.js core.
    on Sep 28, 2017
  3. jasnell commented on Sep 28, 2017

    @jasnell
    Member

    Yes, the read only was intentional in order to explicitly prevent blind overriding. I believe the property is still configurable tho. It's been a while tho so I may be wrong

  4. jdalton commented on Sep 28, 2017

    @jdalton
    MemberAuthor

    Yes, the read only was intentional in order to explicitly prevent blind overriding.

    This applies to CJS code as well, right?

    Is there a user-land scenario in mind, around augmenting Node specific errors, that you're wanting to prevent?

    I'm wondering if the user-land code should have to worry about it. To user-land code an error object is an error object. It could be a syntax error, or some other kind of error, and now code will have to branch for Node specific error objects or handle all error objects as tricky ones (which I'd assume is not the usual case).

  5. jasnell commented on Sep 28, 2017

    @jasnell
    Member

    I'm not against changing it. There is a side effect in that the code is used in the name property, so it's not entirely free

  6. jdalton commented on Sep 28, 2017

    @jdalton
    MemberAuthor

    There is a side effect in that the code is used in the name property, so it's not entirely free

    The symbol prop is used in the name so .code and .name can be modified independently.

  7. evanlucas commented on Sep 28, 2017

    @evanlucas
    Contributor

    I would be +1 on changing. I've seen usage of overwriting Error#code some.

  8. jasnell commented on Sep 28, 2017

    @jasnell
    Member

    What I mean is that changing code would make it out of sync with the name. We should decide whether those should be kept in sync automatically.

  9. jdalton commented on Sep 28, 2017

    @jdalton
    MemberAuthor

    We should decide whether those should be kept in sync automatically

    Since the .code and .name props aren't tied together (.name doesn't rely on .code) I think it'd be fine to allow augmenting to be yolo (getting too fancy with syncing seems like unnecessary overhead).

  10. jasnell commented on Sep 28, 2017

    @jasnell
    Member

    That's the answer I'd be hoping for ;)

  11. Trott commented on Sep 30, 2017

    @Trott
    Member

    Proposed quick fix in #15694

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    errorsIssues and PRs related to JavaScript errors originating in Node.js core.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions