Skip to content

Commit

Permalink
fix: emit setup errors not caused by closed channel
Browse files Browse the repository at this point in the history
Fixes #95
  • Loading branch information
luddd3 committed Aug 24, 2021
1 parent 69f1da3 commit 7c5fe10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/ChannelWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ export default class ChannelWrapper extends EventEmitter {
this._setups.map((setupFn) =>
// TODO: Use a timeout here to guard against setupFns that never resolve?
pb.call(setupFn, this, channel).catch((err) => {
if (this._channel) {
this.emit('error', err, { name: this.name });
} else {
// Don't emit an error if setups failed because the channel was closing.
if (err.name === 'IllegalOperationError' && err.message === 'Channel closed') {
// Don't emit an error if setups failed because the channel closed.
return;
}
this.emit('error', err, { name: this.name });
})
)
).then(() => {
Expand Down
4 changes: 3 additions & 1 deletion test/ChannelWrapperTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ describe('ChannelWrapper', function () {

const setup2 = sinon.spy(() =>
promiseTools.delay(20).then(function () {
throw new Error('Boom!');
const e = new Error('Channel closed');
e.name = 'IllegalOperationError';
throw e;
})
);

Expand Down

0 comments on commit 7c5fe10

Please sign in to comment.