Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

chore: replace err-code with CodeError #82

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

tabcat
Copy link
Contributor

@tabcat tabcat commented Jan 14, 2023

Related: libp2p/js-libp2p#1269

  • deps: bump @libp2p/interfaces
  • deps: remove err-code
  • chore: replace err-code with CodeError

@tabcat
Copy link
Contributor Author

tabcat commented Jan 14, 2023

@wemeetagain src/error.ts contains all usage of errcode. how should this be changed?

@tabcat tabcat marked this pull request as ready for review February 15, 2023 13:18
@tabcat
Copy link
Contributor Author

tabcat commented Feb 15, 2023

@wemeetagain I think this solution is pretty good. There is a breaking change but might not be relevant.

src/error.ts Outdated
Comment on lines 90 to 100
export class OverStreamLimitError extends WebRTCTransportError {
constructor (msg: string) {
super(msg)
constructor (dir: Direction, proto: string) {
const code = dir === 'inbound' ? codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS : codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS
super(`${dir} stream limit reached for protocol - ${proto}`, code)
this.name = 'WebRTC/OverStreamLimitError'
}
}

export function overStreamLimit (dir: Direction, proto: string) {
const code = dir === 'inbound' ? codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS : codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS
return errCode(new OverStreamLimitError(`${dir} stream limit reached for protocol - ${proto}`), code)
return new OverStreamLimitError(dir, proto)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change has to do with exported OverStreamLimitError parameter change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here, we could have a default value for proto param in the OverStreamLimitError constructor (e.g. unknown). We could add TODOs and make the breaking changes with a planned major version increase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make proto in overStreamLimit optional; note this would be adding a change.
The parameter change I made has to do with the OverStreamLimitError which completely changes the parameters.
I'll undo the breaking parts and add a note.

@tabcat
Copy link
Contributor Author

tabcat commented Feb 15, 2023

Wondering if the Error returning Functions are necessary. They could just be removed as they don't do much now.

src/error.ts Outdated
Comment on lines 17 to 22
export class WebRTCTransportError extends Error {
constructor (msg: string) {
super(`WebRTC transport error: ${msg}`)
export class WebRTCTransportError extends CodeError {
constructor (msg: string, code: string) {
super(`WebRTC transport error: ${msg}`, code)
this.name = 'WebRTCTransportError'
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other breaking change

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid the breaking change by making the parameter optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty string fine?

@tabcat
Copy link
Contributor Author

tabcat commented Feb 16, 2023

Lint is failing from a bug in esquery 1.4.1 estools/esquery#135

Do not rerun actions until fix is merged

@p-shahi
Copy link
Member

p-shahi commented Feb 21, 2023

@tabcat I merged the aegir PR which I think has the fix for the esquery issue.

@ddimaria
Copy link
Collaborator

@tabcat can you resolve the conflicts? I think Chinmay needed to update the return type related to the aegir update, so it's probably a comb on "yours" and "theirs".

@tabcat tabcat force-pushed the chore/code-error branch 2 times, most recently from e99350d to 5f62fa6 Compare February 22, 2023 19:10
@p-shahi
Copy link
Member

p-shahi commented Feb 28, 2023

@ddimaria @ckousik looks like @tabcat 's resolved conflicts. Let's try to get this merged by end of week?

@ddimaria
Copy link
Collaborator

@ddimaria @ckousik looks like @tabcat 's resolved conflicts. Let's try to get this merged by end of week?

There are lint errors in CI. @tabcat can you resolve them? If not, I can tackle this today @p-shahi

@tabcat
Copy link
Contributor Author

tabcat commented Feb 28, 2023

My mistake, I'll take care of this right now

deps: remove err-code

replace errcode with CodeError

remove breaking changes

fix linter errors
@ddimaria ddimaria merged commit cfa6494 into libp2p:main Feb 28, 2023
github-actions bot pushed a commit that referenced this pull request Mar 30, 2023
## [1.0.5](v1.0.4...v1.0.5) (2023-03-30)

### Bug Fixes

* correction package.json exports types path ([#103](#103)) ([c78851f](c78851f))

### Trivial Changes

* replace err-code with CodeError ([#82](#82)) ([cfa6494](cfa6494))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([f0ae5e7](f0ae5e7))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([4c8806c](4c8806c))
@github-actions
Copy link

🎉 This PR is included in version 1.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants