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

Commit

Permalink
refactor: replace err-code with CodeError
Browse files Browse the repository at this point in the history
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p/js-libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/interfaces@3.2.0 to dependencies
- uses CodeError in place of err-code
  • Loading branch information
tabcat committed Jan 9, 2023
1 parent 4f0939f commit aad13d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/multistream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -82,12 +82,12 @@ export async function read (reader: Reader, options?: AbortOptions): Promise<Uin
)

if (buf == null || buf.length === 0) {
throw errCode(new Error('no buffer returned'), 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
throw new CodeError('no buffer returned', 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
}

if (buf.get(buf.byteLength - 1) !== NewLine[0]) {
log.error('Invalid mss message - missing newline - %s', buf.subarray())
throw errCode(new Error('missing newline'), 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
throw new CodeError('missing newline', 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
}

return buf.sublist(0, -1) // Remove newline
Expand Down
6 changes: 3 additions & 3 deletions src/select.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logger } from '@libp2p/logger'
import errCode from 'err-code'
import { CodeError } from '@libp2p/interfaces/errors'
import * as multistream from './multistream.js'
import { handshake } from 'it-handshake'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
Expand Down Expand Up @@ -102,7 +102,7 @@ export async function select (stream: Duplex<any>, protocols: string | string[],
}

rest()
throw errCode(new Error('protocol selection failed'), 'ERR_UNSUPPORTED_PROTOCOL')
throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL')
}

/**
Expand Down Expand Up @@ -147,7 +147,7 @@ export function lazySelect (stream: Duplex<any>, 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
Expand Down

0 comments on commit aad13d0

Please sign in to comment.