Skip to content

discuss: move error codes in internal/errors into separate module #14216

Description

@starkwang

The error codes in internal/errors are some string constants. When throw an error, we directly use these string like:

throw new TypeError('ERR_INVALID_CALLBACK');

Using a plain string has many problems: No auto complete, Easy for typo, Difficult to change the error code......

I think we should migrate these string constants to a new file (e.g. internal/error_codes.js):

export const ERR_INVALID_CALLBACK = 'ERR_INVALID_CALLBACK';
// more error codes......

Then we can use these codes after import them:

import * as codes from 'internal/error_codes';

throw new TypeError(codes.ERR_INVALID_CALLBACK);

Activity

  1. added
    errorsIssues and PRs related to JavaScript errors originating in Node.js core.
    feature requestIssues requesting new Node.js features.
    on Jul 13, 2017
  2. XadillaX commented on Jul 13, 2017

    @XadillaX
    Contributor

    I agree with this.

  3. Trott commented on Jul 15, 2017

    @Trott
    Member

    Sounds good to me. /cc @jasnell

  4. jasnell commented on Jul 15, 2017

    @jasnell
    Member

    Dropping them off internals/errors should be easily doable.

  5. apapirovski commented on Mar 3, 2018

    @apapirovski
    Contributor

    The change made by @BridgeAR recently sort of works around this problem in a different way. I believe this can now be closed.

    See #18857 for more info.

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.feature requestIssues requesting new Node.js features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions