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

Commit

Permalink
fix: throw when a write occurs on a missing stream
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed May 12, 2021
1 parent 198015a commit 0d335e6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/mplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const pipe = require('it-pipe')
const pushable = require('it-pushable')
const log = require('debug')('libp2p:mplex')
const abortable = require('abortable-iterator')
const errCode = require('err-code')
const Coder = require('./coder')
const restrictSize = require('./restrict-size')
const { MessageTypes, MessageTypeNames } = require('./message-types')
Expand Down Expand Up @@ -117,6 +118,9 @@ class Mplex {
}
log('new %s stream %s %s', type, id, name)
const send = msg => {
if (!registry.has(id)) {
throw errCode(new Error('the stream is not in the muxer registry, it may have already been closed'), 'ERR_STREAM_DOESNT_EXIST')
}
if (log.enabled) {
log('%s stream %s %s send', type, id, name, { ...msg, type: MessageTypeNames[msg.type], data: msg.data && msg.data.slice() })
}
Expand Down

0 comments on commit 0d335e6

Please sign in to comment.