From 4dec0ded1a6403c5b3f731dc74359239f960849a Mon Sep 17 00:00:00 2001 From: tabcat Date: Sun, 8 Jan 2023 22:37:30 -0600 Subject: [PATCH] refactor: replace err-code with CodeError 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/index.ts | 36 ++++++++++++++++++------------------ src/utils.ts | 4 ++-- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index b1f2461..86bd5ed 100644 --- a/package.json +++ b/package.json @@ -182,14 +182,13 @@ "@libp2p/interface-peer-id": "^2.0.0", "@libp2p/interface-pubsub": "^3.0.0", "@libp2p/interface-registrar": "^2.0.0", - "@libp2p/interfaces": "^3.0.2", + "@libp2p/interfaces": "^3.2.0", "@libp2p/logger": "^2.0.0", "@libp2p/peer-collections": "^3.0.0", "@libp2p/peer-id": "^2.0.0", "@libp2p/topology": "^4.0.0", "@multiformats/multiaddr": "^11.0.0", "abortable-iterator": "^4.0.2", - "err-code": "^3.0.1", "it-length-prefixed": "^8.0.2", "it-pipe": "^2.0.3", "it-pushable": "^3.0.0", diff --git a/src/index.ts b/src/index.ts index e73509f..b0648a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { logger } from '@libp2p/logger' import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events' -import errcode from 'err-code' +import { CodeError } from '@libp2p/interfaces/errors' import { pipe } from 'it-pipe' import Queue from 'p-queue' import { createTopology } from '@libp2p/topology' @@ -447,22 +447,22 @@ export abstract class PubSubBaseProtocol (maybeArray: T | T[]) { export const toMessage = (message: PubSubRPCMessage): Message => { if (message.from == null) { - throw errcode(new Error('RPC message was missing from'), codes.ERR_MISSING_FROM) + throw new CodeError('RPC message was missing from', codes.ERR_MISSING_FROM) } if (message.sequenceNumber == null || message.from == null || message.signature == null || message.key == null) {