diff --git a/src/client/connection.ts b/src/client/connection.ts index c092b8d8ca..802f1f33f3 100644 --- a/src/client/connection.ts +++ b/src/client/connection.ts @@ -133,7 +133,9 @@ export class Connection { } private _createRemoteObject(parentGuid: string, type: string, guid: string, initializer: any): any { - const parent = this._objects.get(parentGuid)!; + const parent = this._objects.get(parentGuid); + if (!parent) + throw new Error(`Cannot find parent object ${parentGuid} to create ${guid}`); let result: ChannelOwner; initializer = this._replaceGuidsWithChannels(initializer); switch (type) { diff --git a/src/dispatchers/dispatcher.ts b/src/dispatchers/dispatcher.ts index 7fbd537904..7ce5cd2b08 100644 --- a/src/dispatchers/dispatcher.ts +++ b/src/dispatchers/dispatcher.ts @@ -18,7 +18,7 @@ import { EventEmitter } from 'events'; import * as channels from '../protocol/channels'; import { serializeError } from '../protocol/serializers'; import { createScheme, Validator, ValidationError } from '../protocol/validator'; -import { assert, createGuid, debugAssert } from '../utils/utils'; +import { assert, createGuid, debugAssert, isUnderTest } from '../utils/utils'; export const dispatcherSymbol = Symbol('dispatcher'); @@ -75,6 +75,12 @@ export class Dispatcher extends EventEmitter implements chann } _dispatchEvent(method: string, params: Dispatcher | any = {}) { + if (this._disposed) { + if (isUnderTest()) + throw new Error(`${this._guid} is sending "${method}" event after being disposed`); + // Just ignore this event outside of tests. + return; + } this._connection.sendMessageToClient(this._guid, method, params); }