Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fbf6d89

Browse files
committedJan 9, 2023
refactor: replace err-code with CodeError
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
1 parent 53958f0 commit fbf6d89

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
 

‎packages/libp2p-peer-id/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
},
140140
"dependencies": {
141141
"@libp2p/interface-peer-id": "^2.0.0",
142-
"err-code": "^3.0.1",
142+
"@libp2p/interfaces": "^3.2.0",
143143
"multiformats": "^11.0.0",
144144
"uint8arrays": "^4.0.2"
145145
},

‎packages/libp2p-peer-id/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as Digest from 'multiformats/hashes/digest'
55
import { identity } from 'multiformats/hashes/identity'
66
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
77
import { sha256 } from 'multiformats/hashes/sha2'
8-
import errcode from 'err-code'
8+
import { CodeError } from '@libp2p/interfaces/errors'
99
import { Ed25519PeerId, PeerIdType, RSAPeerId, Secp256k1PeerId, symbol } from '@libp2p/interface-peer-id'
1010
import type { MultibaseDecoder } from 'multiformats/bases/interface'
1111
import type { MultihashDigest } from 'multiformats/hashes/interface'
@@ -177,7 +177,7 @@ export function createPeerId (init: PeerIdInit): PeerId {
177177
return new Secp256k1PeerIdImpl(init)
178178
}
179179

180-
throw errcode(new Error('Type must be "RSA", "Ed25519" or "secp256k1"'), 'ERR_INVALID_PARAMETERS')
180+
throw new CodeError('Type must be "RSA", "Ed25519" or "secp256k1"', 'ERR_INVALID_PARAMETERS')
181181
}
182182

183183
export function peerIdFromPeerId (other: any): PeerId {
@@ -193,7 +193,7 @@ export function peerIdFromPeerId (other: any): PeerId {
193193
return new Secp256k1PeerIdImpl(other)
194194
}
195195

196-
throw errcode(new Error('Not a PeerId'), 'ERR_INVALID_PARAMETERS')
196+
throw new CodeError('Not a PeerId', 'ERR_INVALID_PARAMETERS')
197197
}
198198

199199
export function peerIdFromString (str: string, decoder?: MultibaseDecoder<any>): PeerId {

0 commit comments

Comments
 (0)
Please sign in to comment.