WS error logging & stacks trimmed (#448)

* Cleanup error stacks

* Close error code & reason

* Re-add debug throw

* Remove stack

* Cleanup console checks (bullsh*t, wtf did I add these anyway)
This commit is contained in:
Jaco Greeff
2018-12-07 10:07:20 +01:00
committed by GitHub
parent b9215d286f
commit 50103dcfab
5 changed files with 12 additions and 65 deletions
+6 -4
View File
@@ -11,7 +11,9 @@ import WsProvider from '@polkadot/rpc-provider/ws';
import { Codec } from '@polkadot/types/types';
import { Vector, createType } from '@polkadot/types/codec';
import { StorageChangeSet, StorageKey } from '@polkadot/types/index';
import { ExtError, assert, isFunction } from '@polkadot/util';
import { ExtError, assert, isFunction, logger } from '@polkadot/util';
const l = logger('rpc-core');
/**
* @name Rpc
@@ -111,7 +113,7 @@ export default class Rpc implements RpcInterface {
} catch (error) {
const message = `${Rpc.signature(method)}:: ${error.message}`;
console.error(message, error);
l.error(message);
throw new ExtError(message, (error as ExtError).code, undefined);
}
@@ -138,7 +140,7 @@ export default class Rpc implements RpcInterface {
const paramsJson = params.map((param) => param.toJSON());
const update = (error: Error | null, result?: any) => {
if (error) {
console.error(`${Rpc.signature(method)}:: ${error.message}`, error);
l.error(`${Rpc.signature(method)}:: ${error.message}`);
return;
}
@@ -149,7 +151,7 @@ export default class Rpc implements RpcInterface {
} catch (error) {
const message = `${Rpc.signature(method)}:: ${error.message}`;
console.error(message, error);
l.error(message);
throw new ExtError(message, (error as ExtError).code, undefined);
}
+6 -6
View File
@@ -216,7 +216,7 @@ export default class WsProvider implements WSProviderInterface {
// a slight complication in solving - since we cannot rely on the send id, but rather
// need to find the actual subscription id to map it
if (isUndefined(this.subscriptions[subscription])) {
l.warn(`Unable to find active subscription=${subscription}`);
l.debug(() => `Unable to find active subscription=${subscription}`);
return false;
}
@@ -232,8 +232,8 @@ export default class WsProvider implements WSProviderInterface {
this._eventemitter.emit(type, ...args);
}
private onSocketClose = (): void => {
l.debug(() => ['disconnected from', this.endpoint]);
private onSocketClose = (event: CloseEvent): void => {
l.error(`disconnected from ${this.endpoint}::${event.code}: ${event.reason}`);
this._isConnected = false;
this.emit('disconnected');
@@ -246,7 +246,7 @@ export default class WsProvider implements WSProviderInterface {
}
private onSocketError = (error: Event): void => {
l.error(error);
l.debug(() => ['socket error', error]);
}
private onSocketMessage = (message: MessageEvent): void => {
@@ -265,7 +265,7 @@ export default class WsProvider implements WSProviderInterface {
const handler = this.handlers[response.id];
if (!handler) {
l.error(`Unable to find handler for id=${response.id}`);
l.debug(() => `Unable to find handler for id=${response.id}`);
return;
}
@@ -297,7 +297,7 @@ export default class WsProvider implements WSProviderInterface {
const handler = this.subscriptions[subscription];
if (!handler) {
l.error(`Unable to find handler for subscription=${subscription}`);
l.debug(() => `Unable to find handler for subscription=${subscription}`);
return;
}
@@ -1,27 +0,0 @@
// Copyright 2017-2018 @polkadot/rpc-provider authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Ws from './index';
describe('onError', () => {
let ws;
let errorSpy;
beforeEach(() => {
ws = new Ws('ws://127.0.0.1:1234', false);
errorSpy = jest.spyOn(console, 'error');
});
afterEach(() => {
errorSpy.mockRestore();
});
it('logs the error', () => {
ws.onSocketError('test error');
expect(errorSpy).toHaveBeenCalledWith(
expect.anything(), expect.anything(), 'test error'
);
});
});
@@ -6,23 +6,9 @@ import Ws from './index';
describe('onMessageResult', () => {
let ws;
let errorSpy;
beforeEach(() => {
ws = new Ws('ws://127.0.0.1:1234', false);
errorSpy = jest.spyOn(console, 'error');
});
afterEach(() => {
errorSpy.mockRestore();
});
it('fails with log when handler not found', () => {
ws.onSocketMessage({ data: '{"id":2}' });
expect(errorSpy).toHaveBeenCalledWith(
expect.anything(), expect.anything(), 'Unable to find handler for id=2'
);
});
it('calls the handler when found', (done) => {
@@ -6,23 +6,9 @@ import Ws from './index';
describe('onMessageSubscribe', () => {
let ws;
let errorSpy;
beforeEach(() => {
ws = new Ws('ws://127.0.0.1:1234', false);
errorSpy = jest.spyOn(console, 'error');
});
afterEach(() => {
errorSpy.mockRestore();
});
it('fails with log when handler not found', () => {
ws.onSocketMessage({ data: '{"method":"test","params":{"subscription":2}}' });
expect(errorSpy).toHaveBeenCalledWith(
expect.anything(), expect.anything(), 'Unable to find handler for subscription=test::2'
);
});
it('calls the subscriber with data', (done) => {