Skip to content

Commit

Permalink
fix(rpc): ensure better error messages when rpc misbehaves (#3838)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
dgozman authored Sep 10, 2020
1 parent ed3b00e commit 46f9151
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/client/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion src/dispatchers/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 46f9151

Please sign in to comment.