Ensure that the cancel
/error
methods on Streams are always called with valid reason
arguments
This commit is contained in:
parent
02bdacef42
commit
74f5a59f43
@ -223,6 +223,7 @@ MessageHandler.prototype = {
|
||||
},
|
||||
|
||||
cancel: (reason) => {
|
||||
assert(reason instanceof Error, 'cancel must have a valid reason');
|
||||
let cancelCapability = createPromiseCapability();
|
||||
this.streamControllers[streamId].cancelCall = cancelCapability;
|
||||
this.streamControllers[streamId].isClosed = true;
|
||||
@ -287,6 +288,7 @@ MessageHandler.prototype = {
|
||||
},
|
||||
|
||||
error(reason) {
|
||||
assert(reason instanceof Error, 'error must have a valid reason');
|
||||
if (this.isCancelled) {
|
||||
return;
|
||||
}
|
||||
|
@ -13,7 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AbortException, createPromiseCapability } from '../../src/shared/util';
|
||||
import {
|
||||
AbortException, createPromiseCapability, UnknownErrorException
|
||||
} from '../../src/shared/util';
|
||||
import { LoopbackPort } from '../../src/display/api';
|
||||
import { MessageHandler } from '../../src/shared/message_handler';
|
||||
|
||||
@ -149,7 +151,7 @@ describe('message_handler', function () {
|
||||
return sink.ready;
|
||||
}).then(() => {
|
||||
log += 'e';
|
||||
sink.error('error');
|
||||
sink.error(new Error('should not read when errored'));
|
||||
});
|
||||
});
|
||||
let messageHandler1 = new MessageHandler('main', 'worker', port);
|
||||
@ -171,7 +173,8 @@ describe('message_handler', function () {
|
||||
return reader.read();
|
||||
}).catch((reason) => {
|
||||
expect(log).toEqual('01pe');
|
||||
expect(reason).toEqual('error');
|
||||
expect(reason instanceof UnknownErrorException).toEqual(true);
|
||||
expect(reason.message).toEqual('should not read when errored');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user