Skip to content

Errors - use .name instead of .code #2634

@achingbrain

Description

@achingbrain

We use .code as a way to identify certain error conditions independent of the error message (which may be localised into the users' language) - ERR_STREAM_RESET, ERR_INVALID_PARAMETERS, etc.

This property was largely inspired by node.js' use of .code, and is not idiomatic JavaScript which seems to have subsequently coalesced around the .name property of the Error type for this sort of thing instead.

There's a ongoing effort to introduce error codes to libp2p, and supplying any encountered code to the application is marked MUST.

The natural thing of js to do would be to throw an Error with the appropriate numeric .code property, which conflicts with the current implementation.

We should refactor our use of errors to use a .name string property (e.g. StreamResetError, InvalidParametersError, etc) which frees up the .code property to receive an error code from the remote node specifying why the stream was reset.

This is a breaking change that would cause [email protected] to be released.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions