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

chore: replace err-code with CodeError #36

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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