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

Use/create a more intuitive errcode #1269

Closed
wemeetagain opened this issue Jun 22, 2022 · 15 comments
Closed

Use/create a more intuitive errcode #1269

wemeetagain opened this issue Jun 22, 2022 · 15 comments

Comments

@wemeetagain
Copy link
Member

Current usage of errcode is not intuitive.
example:

throw new errcode(new Error('error in foo'), ERR_FOO, { foo: bar })

Prefer an implementation like:

export class CodeError<T extends Record<string, any>> extends Error {
  code: string
  props: T

  constructor(message: string, code: string, props?: T) {
    super(message)

    this.code = code
    this.props = props ?? {} as T
  }
}

with usage then like:

throw new CodeError('error in foo', ERR_FOO, { foo: bar })
@wemeetagain wemeetagain added the need/triage Needs initial labeling and prioritization label Jun 22, 2022
@p-shahi p-shahi added the P2 Medium: Good to have, but can wait until someone steps up label Sep 27, 2022
@achingbrain
Copy link
Member

achingbrain commented Oct 5, 2022

This is a great first issue that would suit someone looking to get started helping build libp2p!

To complete this:

  1. Create a new repo
  2. Export CodeError class (defined in OP)
  3. Write tests
  4. Open PRs to @libp2p/* repos replacing use of the err-code module with the new class

@achingbrain achingbrain added help wanted Seeking public contribution on this issue P3 Low: Not priority right now good first issue Good issue for new contributors and removed P2 Medium: Good to have, but can wait until someone steps up need/triage Needs initial labeling and prioritization labels Oct 5, 2022
achingbrain added a commit to libp2p/js-libp2p-interfaces that referenced this issue Jan 3, 2023
Adds [CodeError](libp2p/js-libp2p#1269) to errors.ts

Related: libp2p/js-libp2p-crypto#284 (comment)

Added public to props and code to match AbortCode style.

Also recently added the custom [Error.name](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name) property to [code-err](https://github.com/tabcat/code-err) implementation.

Co-authored-by: Alex Potsides <alex@achingbrain.net>
@tabcat
Copy link
Contributor

tabcat commented Jan 4, 2023

Will look at completing this week now that CodeError is available.

@tabcat
Copy link
Contributor

tabcat commented Jan 5, 2023

Tracking PRs needed to close this issue.
Have started by adding all relevant @libp2p/* packages like requested.
If changes to the list are needed let me know.

libp2p direct deps

additional packages

@tabcat
Copy link
Contributor

tabcat commented Jan 5, 2023

Replacing the imports is very easy.

Here is some naive regex I'm using to replace the implementations for anyone looking to do this in their own projects. Works for most of the ways errCode is being used currently.

find: errcode(\(\n?\s*)new .*Error\((.*)\)(,\n?\s*.*\n?\s*\)\n?)
replace: new CodeError$1$2$3

@tabcat
Copy link
Contributor

tabcat commented Jan 8, 2023

Have crossed out webrtc- star and peer from list above. These packages look like they will be deprecated; can add them back if necessary.

There is also an issue with replacing err-code with CodeError in the libp2p pr. It has to do with the supplied props being exposed by CodeError from error.props object instead of the error object directly. This could affect code relying on how err-code exposes the props, see more in the pr to the main libp2p repo in the list above.

tabcat added a commit to tabcat/js-libp2p-multistream-select that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-mplex that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-record that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-peer-id that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [#1269](libp2p/js-libp2p#1269)

Changes (only affect peer-id package)

- added @libp2p/interfaces@3.2.0 to the to use the new CodeError export
- removes err-code from dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-kad-dht that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-peer-record that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-peer-store that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-pubsub that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-tcp that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-utils that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-interfaces that referenced this issue Jan 9, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
@p-shahi
Copy link
Member

p-shahi commented Feb 14, 2023

@tabcat looks like all but a few prs remain for this effort. Need some help shepherding those along?

Another module that we likely need this change in is https://github.com/libp2p/js-libp2p-webtransport

@tabcat
Copy link
Contributor

tabcat commented Feb 15, 2023

I meant to update this thread.

libp2p/js-libp2p-interfaces#334 needs attention. I'm not sure how to bump the js-libp2p-interfaces package in js-libp2p-interfaces/packages/interface-mocks.

#1532 just needs the proper breaking change notice to be added by me

Another module that we likely need this change in is https://github.com/libp2p/js-libp2

I'll add it to the list

tabcat added a commit to tabcat/js-libp2p-interfaces that referenced this issue Feb 15, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
tabcat added a commit to tabcat/js-libp2p-interfaces that referenced this issue Feb 15, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
mpetrunic added a commit to libp2p/js-libp2p-interfaces that referenced this issue Feb 22, 2023
* chore: replace err-code with CodeError

Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code

* remove err-code dep

---------

Co-authored-by: Marin Petrunic <marin.petrunic@gmail.com>
github-actions bot pushed a commit to libp2p/js-libp2p-interfaces that referenced this issue Feb 22, 2023
## [@libp2p/interface-mocks-v9.1.2](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-mocks-v9.1.1...@libp2p/interface-mocks-v9.1.2) (2023-02-22)

### Bug Fixes

* replace err-code with CodeError ([#334](#334)) ([a909d41](a909d41)), closes [js-libp2p#1269](libp2p/js-libp2p#1269)
github-actions bot pushed a commit to libp2p/js-libp2p-peer-store that referenced this issue Feb 28, 2023
## [6.0.1](v6.0.0...v6.0.1) (2023-02-28)

### Trivial Changes

* replace err-code with CodeError ([#53](#53)) ([e6b87d7](e6b87d7)), closes [js-libp2p#1269](libp2p/js-libp2p#1269)
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([1139dc4](1139dc4))

### Documentation

* Update API link ([#65](#65)) ([1b75110](1b75110)), closes [#64](#64)
@tabcat
Copy link
Contributor

tabcat commented Mar 2, 2023

Adding js-libp2p-keychain to the todo list

@tabcat
Copy link
Contributor

tabcat commented Mar 2, 2023

It looks like src/keychain/cms.ts was completely removed from the keychain as a result of the move from the js-libp2p repo. That was the only part resulting in breaking changes to any libp2p repos.

github-actions bot pushed a commit to libp2p/js-libp2p-kad-dht that referenced this issue Mar 10, 2023
## [7.0.1](v7.0.0...v7.0.1) (2023-03-10)

### Bug Fixes

* correct `KBucketTree` types ([#426](#426)) ([ea8e6d0](ea8e6d0)), closes [/github.com/tristanls/k-bucket/blob/3aa5b4f1dacb835752995a25409ab319d2070b9e/index.js#L413](https://github.com/libp2p//github.com/tristanls/k-bucket/blob/3aa5b4f1dacb835752995a25409ab319d2070b9e/index.js/issues/L413)
* update p-queue types ([#428](#428)) ([f5b85fc](f5b85fc))

### Trivial Changes

* replace err-code with CodeError ([#413](#413)) ([e05d2a0](e05d2a0)), closes [js-libp2p#1269](libp2p/js-libp2p#1269)
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([a70ab3f](a70ab3f))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([1652c6c](1652c6c))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([ea13c2a](ea13c2a))
github-actions bot pushed a commit to libp2p/js-libp2p-peer-record that referenced this issue Mar 10, 2023
## [5.0.1](v5.0.0...v5.0.1) (2023-03-10)

### Trivial Changes

* replace err-code with CodeError ([#42](#42)) ([b76d07f](b76d07f)), closes [js-libp2p#1269](libp2p/js-libp2p#1269)
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([157d49d](157d49d))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([920dfd3](920dfd3))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([1ef05ef](1ef05ef))
* upgrade `aegir` to `38.1.2` ([#48](#48)) ([e0fd5e3](e0fd5e3))

### Dependencies

* bump protons-runtime from 4.0.2 to 5.0.0 ([#45](#45)) ([83958a5](83958a5))
github-actions bot pushed a commit to libp2p/js-libp2p-record that referenced this issue Mar 10, 2023
## [3.0.1](v3.0.0...v3.0.1) (2023-03-10)

### Trivial Changes

* replace err-code with CodeError ([#71](#71)) ([a843ae4](a843ae4)), closes [js-libp2p#1269](libp2p/js-libp2p#1269)
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([3982918](3982918))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([79984c0](79984c0))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([7ccccc7](7ccccc7))

### Dependencies

* **dev:** bump aegir from 37.12.1 to 38.1.7 ([#84](#84)) ([4cc5935](4cc5935))
achingbrain pushed a commit to libp2p/js-libp2p-keychain that referenced this issue Mar 13, 2023
replace err-code with CodeError from @libp2p/interfaces

Related: libp2p/js-libp2p#1269
github-actions bot pushed a commit to libp2p/js-libp2p-utils that referenced this issue Mar 17, 2023
## [3.0.5](v3.0.4...v3.0.5) (2023-03-17)

### Trivial Changes

* replace err-code with CodeError ([#70](#70)) ([beb252d](beb252d)), closes [js-libp2p#1269](libp2p/js-libp2p#1269)
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([acad1fe](acad1fe))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([1b96837](1b96837))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([10d6e7a](10d6e7a))

### Dependencies

* bump @multiformats/multiaddr from 11.6.1 to 12.0.0 ([#83](#83)) ([3eeeeba](3eeeeba))
* **dev:** bump aegir from 37.12.1 to 38.1.7 ([#80](#80)) ([2c262ba](2c262ba))
achingbrain added a commit that referenced this issue Mar 20, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: #1269

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code

---------

Co-authored-by: achingbrain <alex@achingbrain.net>
@tabcat
Copy link
Contributor

tabcat commented Mar 20, 2023

Do you think this can be closed now? @wemeetagain

@maschad
Copy link
Member

maschad commented Mar 20, 2023

Thanks for all the great work @tabcat! There are some deps which were missing from the list, I updated the comment to include them as well as to highlight why some repos were unaffected. Almost there!

github-actions bot pushed a commit to libp2p/js-libp2p-mplex that referenced this issue Mar 21, 2023
## [7.1.2](v7.1.1...v7.1.2) (2023-03-21)

### Trivial Changes

* replace err-code with CodeError ([#242](#242)) ([8d58a3b](8d58a3b)), closes [js-libp2p#1269](libp2p/js-libp2p#1269)
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([54de88d](54de88d))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([df03e8d](df03e8d))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([9c3f235](9c3f235))

### Dependencies

* **dev:** bump typescript from 4.9.5 to 5.0.2 ([#256](#256)) ([a3590af](a3590af))
* **dev:** Upgrade aegir to 38.1.7 ([#257](#257)) ([e0bf45a](e0bf45a))
github-actions bot pushed a commit to libp2p/js-libp2p-multistream-select that referenced this issue Mar 31, 2023
## [3.1.3](v3.1.2...v3.1.3) (2023-03-31)

### Trivial Changes

* replace err-code with CodeError ([#36](#36)) ([fc2aefd](fc2aefd)), closes [js-libp2p#1269](libp2p/js-libp2p#1269)
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([1861a94](1861a94))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([0f312c0](0f312c0))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([6a277a6](6a277a6))

### Dependencies

* bump it-merge from 2.0.1 to 3.0.0 ([#51](#51)) ([129166b](129166b))
* **dev:** bump it-all from 2.0.1 to 3.0.1 ([#50](#50)) ([d8420a0](d8420a0))
achingbrain pushed a commit to multiformats/js-multiaddr that referenced this issue Apr 5, 2023
Related: libp2p/js-libp2p#1269

- deps: install @libp2p/interfaces
- fix: replace err-code with CodeError
- deps: remove err-code
@p-shahi
Copy link
Member

p-shahi commented May 30, 2023

@tabcat thank you for driving this! It's been shipped so we'll close this.

@p-shahi p-shahi closed this as completed May 30, 2023
maschad pushed a commit to maschad/js-libp2p that referenced this issue Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants