From beb252d79f69d0f49d1fa4fd664a49e33ff80cd3 Mon Sep 17 00:00:00 2001 From: tabcat Date: Fri, 13 Jan 2023 14:03:34 -0600 Subject: [PATCH] chore: replace err-code with CodeError (#70) 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 | 2 +- src/ip-port-to-multiaddr.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 056cb74766..b33e551b05 100644 --- a/package.json +++ b/package.json @@ -179,10 +179,10 @@ "@achingbrain/ip-address": "^8.1.0", "@libp2p/interface-connection": "^3.0.2", "@libp2p/interface-peer-store": "^1.2.1", + "@libp2p/interfaces": "^3.2.0", "@libp2p/logger": "^2.0.0", "@multiformats/multiaddr": "^11.0.0", "abortable-iterator": "^4.0.2", - "err-code": "^3.0.1", "is-loopback-addr": "^2.0.1", "it-stream-types": "^1.0.4", "private-ip": "^3.0.0", diff --git a/src/ip-port-to-multiaddr.ts b/src/ip-port-to-multiaddr.ts index 12cfe40e1e..35144d0f7d 100644 --- a/src/ip-port-to-multiaddr.ts +++ b/src/ip-port-to-multiaddr.ts @@ -1,6 +1,6 @@ import { logger } from '@libp2p/logger' import { multiaddr } from '@multiformats/multiaddr' -import errCode from 'err-code' +import { CodeError } from '@libp2p/interfaces/errors' import { Address4, Address6 } from '@achingbrain/ip-address' const log = logger('libp2p:ip-port-to-multiaddr') @@ -16,7 +16,7 @@ export const Errors = { */ export function ipPortToMultiaddr (ip: string, port: number | string) { if (typeof ip !== 'string') { - throw errCode(new Error(`invalid ip provided: ${ip}`), Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions + throw new CodeError(`invalid ip provided: ${ip}`, Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions } if (typeof port === 'string') { @@ -24,7 +24,7 @@ export function ipPortToMultiaddr (ip: string, port: number | string) { } if (isNaN(port)) { - throw errCode(new Error(`invalid port provided: ${port}`), Errors.ERR_INVALID_PORT_PARAMETER) + throw new CodeError(`invalid port provided: ${port}`, Errors.ERR_INVALID_PORT_PARAMETER) } try { @@ -42,6 +42,6 @@ export function ipPortToMultiaddr (ip: string, port: number | string) { } catch (err) { const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}` log.error(errMsg) - throw errCode(new Error(errMsg), Errors.ERR_INVALID_IP) + throw new CodeError(errMsg, Errors.ERR_INVALID_IP) } }