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 Oct 15, 2020
1 parent 53074b0 commit c06dd96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"homepage": "https://github.com/libp2p/js-libp2p-mplex#readme",
"devDependencies": {
"aegir": "^27.0.0",
"libp2p-interfaces": "^0.6.0",
"libp2p-interfaces": "libp2p/js-libp2p-interfaces#feat/streams",
"p-defer": "^3.0.0",
"random-bytes": "^1.0.0",
"random-int": "^2.0.0",
Expand All @@ -55,6 +55,7 @@
"abortable-iterator": "^3.0.0",
"bl": "^4.0.0",
"debug": "^4.2.0",
"err-code": "^2.0.3",
"it-pipe": "^1.1.0",
"it-pushable": "^1.4.0",
"varint": "^5.0.0"
Expand Down
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 c06dd96

Please sign in to comment.