Ensure that Error
s are handled correctly when using postMessage
with Streams in MessageHandler
Having recently worked with this code, it struck me that most of the `postMessage` calls where `Error`s are involved have never been correctly implemented (i.e. missing `wrapReason` calls).
This commit is contained in:
parent
e59b11860d
commit
02bdacef42
@ -231,7 +231,7 @@ MessageHandler.prototype = {
|
|||||||
targetName,
|
targetName,
|
||||||
stream: StreamKind.CANCEL,
|
stream: StreamKind.CANCEL,
|
||||||
streamId,
|
streamId,
|
||||||
reason,
|
reason: wrapReason(reason),
|
||||||
});
|
});
|
||||||
// Return Promise to signal success or failure.
|
// Return Promise to signal success or failure.
|
||||||
return cancelCapability.promise;
|
return cancelCapability.promise;
|
||||||
@ -296,7 +296,7 @@ MessageHandler.prototype = {
|
|||||||
targetName,
|
targetName,
|
||||||
stream: StreamKind.ERROR,
|
stream: StreamKind.ERROR,
|
||||||
streamId,
|
streamId,
|
||||||
reason,
|
reason: wrapReason(reason),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ MessageHandler.prototype = {
|
|||||||
targetName,
|
targetName,
|
||||||
stream: StreamKind.START_COMPLETE,
|
stream: StreamKind.START_COMPLETE,
|
||||||
streamId,
|
streamId,
|
||||||
reason,
|
reason: wrapReason(reason),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -397,7 +397,7 @@ MessageHandler.prototype = {
|
|||||||
targetName,
|
targetName,
|
||||||
stream: StreamKind.PULL_COMPLETE,
|
stream: StreamKind.PULL_COMPLETE,
|
||||||
streamId,
|
streamId,
|
||||||
reason,
|
reason: wrapReason(reason),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -450,7 +450,7 @@ MessageHandler.prototype = {
|
|||||||
targetName,
|
targetName,
|
||||||
stream: StreamKind.CANCEL_COMPLETE,
|
stream: StreamKind.CANCEL_COMPLETE,
|
||||||
streamId,
|
streamId,
|
||||||
reason,
|
reason: wrapReason(reason),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.streamSinks[data.streamId].sinkCapability.
|
this.streamSinks[data.streamId].sinkCapability.
|
||||||
|
@ -142,11 +142,13 @@ describe('message_handler', function () {
|
|||||||
sink.onCancel = function (reason) {
|
sink.onCancel = function (reason) {
|
||||||
log += 'c';
|
log += 'c';
|
||||||
};
|
};
|
||||||
|
log += '0';
|
||||||
sink.ready.then(() => {
|
sink.ready.then(() => {
|
||||||
|
log += '1';
|
||||||
sink.enqueue([1, 2, 3, 4], 4);
|
sink.enqueue([1, 2, 3, 4], 4);
|
||||||
return sink.ready;
|
return sink.ready;
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
log += 'error';
|
log += 'e';
|
||||||
sink.error('error');
|
sink.error('error');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -161,14 +163,14 @@ describe('message_handler', function () {
|
|||||||
let reader = readable.getReader();
|
let reader = readable.getReader();
|
||||||
|
|
||||||
sleep(10).then(() => {
|
sleep(10).then(() => {
|
||||||
expect(log).toEqual('');
|
expect(log).toEqual('01');
|
||||||
return reader.read();
|
return reader.read();
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
expect(result.value).toEqual([1, 2, 3, 4]);
|
expect(result.value).toEqual([1, 2, 3, 4]);
|
||||||
expect(result.done).toEqual(false);
|
expect(result.done).toEqual(false);
|
||||||
return reader.read();
|
return reader.read();
|
||||||
}).then(() => {
|
}).catch((reason) => {
|
||||||
}, (reason) => {
|
expect(log).toEqual('01pe');
|
||||||
expect(reason).toEqual('error');
|
expect(reason).toEqual('error');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user