Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors - use .name instead of .code #2634

Closed
achingbrain opened this issue Jul 24, 2024 · 1 comment
Closed

Errors - use .name instead of .code #2634

achingbrain opened this issue Jul 24, 2024 · 1 comment
Labels
exploration version-2.0 PRs that will be released in libp2p v2

Comments

@achingbrain
Copy link
Member

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.

@achingbrain achingbrain added need/triage Needs initial labeling and prioritization exploration version-2.0 PRs that will be released in libp2p v2 and removed need/triage Needs initial labeling and prioritization labels Jul 24, 2024
@SgtPooki
Copy link
Member

I believe this was resolved by #2655

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exploration version-2.0 PRs that will be released in libp2p v2
Projects
None yet
Development

No branches or pull requests

2 participants