fix(rpc): ensure better error messages when rpc misbehaves (#3838)

- Print parentGuid when it is not available for __create__.
  Some bots show generic "something is undefined" error - let's
  get better information about the failure.

- Ignore events on disposed objects outside of tests.
  Some bots show this happening for "previewUpdated" - let's see
  whether there are more important events that misbehave.
This commit is contained in:
Dmitry Gozman 2020-09-10 16:20:12 -07:00 committed by GitHub
parent ed3b00efdf
commit 46f9151795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -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<any, any>;
initializer = this._replaceGuidsWithChannels(initializer);
switch (type) {

View File

@ -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<Type, Initializer> extends EventEmitter implements chann
}
_dispatchEvent(method: string, params: Dispatcher<any, any> | 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);
}