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

Commit

Permalink
chore: log invalid buffer (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrunic authored Nov 15, 2022
1 parent 3caf904 commit 1fce957
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/multistream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import type { Source } from 'it-stream-types'
import type { Reader } from 'it-reader'
import type { MultistreamSelectInit } from '.'
import { MAX_PROTOCOL_LENGTH } from './constants.js'
import { logger } from '@libp2p/logger'

const log = logger('libp2p:mss')

const NewLine = uint8ArrayFromString('\n')

Expand Down Expand Up @@ -83,6 +86,7 @@ export async function read (reader: Reader, options?: AbortOptions): Promise<Uin
}

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')
}

Expand Down

0 comments on commit 1fce957

Please sign in to comment.