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

chore: log invalid buffer #30

Merged
merged 1 commit into from
Nov 15, 2022
Merged
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
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