From fc2aefdec0db9a2b39fe8259881cf3a2693027cb Mon Sep 17 00:00:00 2001 From: tabcat Date: Fri, 13 Jan 2023 13:54:15 -0600 Subject: [PATCH] chore: replace err-code with CodeError (#36) Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](https://github.com/libp2p/js-libp2p-interfaces/pull/314) Related: [js-libp2p#1269](https://github.com/libp2p/js-libp2p/issues/1269) Changes - removes err-code from dependencies - adds @libp2p/interfaces@3.2.0 to dependencies - uses CodeError in place of err-code --- package.json | 3 +-- src/multistream.ts | 6 +++--- src/select.ts | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index fd29317..3ea6ef2 100644 --- a/package.json +++ b/package.json @@ -143,10 +143,9 @@ "docs": "aegir docs" }, "dependencies": { - "@libp2p/interfaces": "^3.0.2", + "@libp2p/interfaces": "^3.2.0", "@libp2p/logger": "^2.0.0", "abortable-iterator": "^4.0.2", - "err-code": "^3.0.1", "it-first": "^2.0.0", "it-handshake": "^4.1.2", "it-length-prefixed": "^8.0.3", diff --git a/src/multistream.ts b/src/multistream.ts index 7d33914..cd2b932 100644 --- a/src/multistream.ts +++ b/src/multistream.ts @@ -2,7 +2,7 @@ import { Uint8ArrayList } from 'uint8arraylist' import * as lp from 'it-length-prefixed' import { pipe } from 'it-pipe' -import errCode from 'err-code' +import { CodeError } from '@libp2p/interfaces/errors' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import first from 'it-first' import { abortableSource } from 'abortable-iterator' @@ -82,12 +82,12 @@ export async function read (reader: Reader, options?: AbortOptions): Promise, protocols: string | string[], } rest() - throw errCode(new Error('protocol selection failed'), 'ERR_UNSUPPORTED_PROTOCOL') + throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL') } /** @@ -147,7 +147,7 @@ export function lazySelect (stream: Duplex, protocol: string): ProtocolStre response = await multistream.readString(byteReader) } if (response !== protocol) { - throw errCode(new Error('protocol selection failed'), 'ERR_UNSUPPORTED_PROTOCOL') + throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL') } for await (const chunk of byteReader) { yield * chunk