Skip to content

Commit

Permalink
[DDW-517] Removes stringifyError calls from Logger.error
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusHurney committed Feb 7, 2019
1 parent 22e9a38 commit baf148c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 67 deletions.
17 changes: 8 additions & 9 deletions source/main/cardano/CardanoNode.js
Expand Up @@ -4,7 +4,6 @@ import type { ChildProcess, spawn, exec } from 'child_process';
import type { WriteStream } from 'fs';
import { toInteger } from 'lodash';
import { environment } from '../environment';
import { stringifyError } from '../../common/utils/logging';
import { deriveProcessNames, deriveStorageKeys, promisedCondition } from './utils';
import { getProcess } from '../utils/processes';
import type {
Expand Down Expand Up @@ -281,7 +280,7 @@ export class CardanoNode {
this._reset();
return Promise.resolve();
} catch (error) {
_log.error('CardanoNode#stop: cardano-node did not stop correctly', { error: `${stringifyError(error)}` });
_log.error('CardanoNode#stop: cardano-node did not stop correctly', { error });
try {
await this.kill();
} catch (killError) {
Expand Down Expand Up @@ -339,7 +338,7 @@ export class CardanoNode {
await this._waitForCardanoToExitOrKillIt();
await this.start(_config, isForced);
} catch (error) {
_log.error('CardanoNode#restart: Could not restart cardano-node', { error: `${stringifyError(error)}` });
_log.error('CardanoNode#restart: Could not restart cardano-node', { error });
this._changeToState(CardanoNodeStates.ERRORED);
return Promise.reject(error);
}
Expand Down Expand Up @@ -478,7 +477,7 @@ export class CardanoNode {

_handleCardanoNodeError = async (error: Error) => {
const { _log } = this;
_log.error('CardanoNode: error', { error: `${stringifyError(error)}` });
_log.error('CardanoNode: error', { error });
this._changeToState(CardanoNodeStates.ERRORED);
this._transitionListeners.onError(error);
await this.restart();
Expand Down Expand Up @@ -586,7 +585,7 @@ export class CardanoNode {
} catch (error) {
_log.error(
`CardanoNode: could not kill ${name} process (PID: ${pid})`,
{ name, pid, error: `${stringifyError(error)}` }
{ name, pid, error }
);
return Promise.reject();
}
Expand Down Expand Up @@ -620,7 +619,7 @@ export class CardanoNode {
_log.debug(`CardanoNode: previous ${processName} process found`, { processName, previousProcess });
return true;
} catch (error) {
_log.error('CardanoNode: _isProcessRunning error', { error: `${stringifyError(error)}` });
_log.error('CardanoNode: _isProcessRunning error', { error });
return false;
}
};
Expand All @@ -647,7 +646,7 @@ export class CardanoNode {
} catch (error) {
this._log.error(
`CardanoNode: _killProcessWithName returned an error attempting to kill ${name} process (PID: ${pid})`,
{ processName: name, pid, error: `${stringifyError(error)}` }
{ processName: name, pid, error }
);
return Promise.reject(error);
}
Expand All @@ -671,7 +670,7 @@ export class CardanoNode {
this._log.info(`CardanoNode: ${identifier} stored successfuly`);
resolve();
} catch (error) {
this._log.error(`CardanoNode: failed to store ${identifier}`, { error: `${stringifyError(error)}` });
this._log.error(`CardanoNode: failed to store ${identifier}`, { error });
reject(error);
}
})
Expand All @@ -692,7 +691,7 @@ export class CardanoNode {
this._log.info(`CardanoNode: get ${identifier} success`, { [`${identifier}`]: data });
resolve(toInteger(data));
} catch (error) {
this._log.error(`CardanoNode: get ${identifier} failed`, { error: `${stringifyError(error)}` });
this._log.error(`CardanoNode: get ${identifier} failed`, { error });
reject(error);
}
})
Expand Down
3 changes: 1 addition & 2 deletions source/main/cardano/setupCardanoNodeMode.js
Expand Up @@ -11,7 +11,6 @@ import {
NODE_STARTUP_TIMEOUT, NODE_UPDATE_TIMEOUT
} from '../config';
import { Logger } from '../utils/logging';
import { stringifyError } from '../../common/utils/logging';
import type { LauncherConfig } from '../config';
import type {
CardanoNodeState,
Expand Down Expand Up @@ -48,7 +47,7 @@ const restartCardanoNode = async (node: CardanoNode) => {
try {
await node.restart();
} catch (error) {
Logger.error('Could not restart CardanoNode', { error: `${stringifyError(error)}` });
Logger.error('Could not restart CardanoNode', { error });
}
};

Expand Down
3 changes: 1 addition & 2 deletions source/main/index.js
Expand Up @@ -20,7 +20,6 @@ import { buildAppMenus } from './utils/buildAppMenus';
import { getLocale } from './utils/getLocale';
import { ensureXDGDataIsSet } from './cardano/config';
import { rebuildApplicationMenu } from './ipc/rebuild-application-menu';
import { stringifyError } from '../common/utils/logging';
import { CardanoNodeStates } from '../common/types/cardano-node.types';
import type { CheckDiskSpaceResponse } from '../common/types/no-disk-space.types';

Expand All @@ -46,7 +45,7 @@ const safeExit = async () => {
Logger.info('Daedalus:safeExit: exiting Daedalus with code 0', { code: 0 });
safeExitWithCode(0);
} catch (error) {
Logger.error('Daedalus:safeExit: cardano-node did not exit correctly', { error: `${stringifyError(error)}` });
Logger.error('Daedalus:safeExit: cardano-node did not exit correctly', { error });
safeExitWithCode(0);
}
};
Expand Down
15 changes: 7 additions & 8 deletions source/main/ipc/compress-logs.js
Expand Up @@ -7,7 +7,6 @@ import { get } from 'lodash';
import { appLogsFolderPath, pubLogsFolderPath } from '../config';
import { Logger } from '../utils/logging';
import { COMPRESS_LOGS } from '../../common/ipc-api';
import { stringifyError } from '../../common/utils/logging';

export default () => {
ipcMain.on(COMPRESS_LOGS.REQUEST, (event, logs, compressedFileName) => {
Expand All @@ -23,9 +22,9 @@ export default () => {
return sender.send(COMPRESS_LOGS.SUCCESS, outputPath);
});

archive.on('error', (err) => {
Logger.error('COMPRESS_LOGS.ERROR', { error: `${stringifyError(err)}` });
return sender.send(COMPRESS_LOGS.ERROR, err);
archive.on('error', (error) => {
Logger.error('COMPRESS_LOGS.ERROR', { error });
return sender.send(COMPRESS_LOGS.ERROR, error);
});

Logger.debug('COMPRESS_LOGS.START');
Expand All @@ -37,10 +36,10 @@ export default () => {
archive.append(stream, { name: logFiles[i] });
}

archive.finalize((err) => {
if (err) {
Logger.error('COMPRESS_LOGS.ERROR', { error: `${stringifyError(err)}` });
return sender.send(COMPRESS_LOGS.ERROR, err);
archive.finalize((error) => {
if (error) {
Logger.error('COMPRESS_LOGS.ERROR', { error });
return sender.send(COMPRESS_LOGS.ERROR, error);
}
});

Expand Down
3 changes: 1 addition & 2 deletions source/main/ipc/parse-redemption-code-from-pdf.js
Expand Up @@ -8,7 +8,6 @@ import {
} from '../../common/crypto/decrypt';
import { PARSE_REDEMPTION_CODE } from '../../common/ipc-api';
import { Logger } from '../utils/logging';
import { stringifyError } from '../../common/utils/logging';

export default () => {
ipcMain.on(PARSE_REDEMPTION_CODE.REQUEST, (event, filePath, decryptionKey, redemptionType) => {
Expand Down Expand Up @@ -39,7 +38,7 @@ export default () => {
fs.writeFileSync(pdfPath, decryptedFile);
isTemporaryDecryptedPdf = true;
} catch (error) {
Logger.error('Error while parsing redemption code', { error: `${stringifyError(error)}` });
Logger.error('Error while parsing redemption code', { error });
sender.send(PARSE_REDEMPTION_CODE.ERROR, error.message);
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions source/main/utils/mainErrorHandler.js
Expand Up @@ -8,17 +8,17 @@ export default (onError?: Function) => {
Logger.info('========== Main Error Handler started ==========');

unhandled({
logger: (error: any) => Logger.error('unhandledException::main', { error: `${stringifyError(error)}` }),
logger: (error: any) => Logger.error('unhandledException::main', { error }),
showDialog: false
});

process.on('uncaughtException', (error: any) => {
const err = `${stringifyError(error)}`;
Logger.error('uncaughtException', { error: `${err}` });
Logger.error('uncaughtException', { error });
if (typeof onError === 'function') onError(err);
});

app.on('gpu-process-crashed', (event: any, killed: boolean) => {
Logger.error(`uncaughtException::gpu-process-crashed: ${killed ? 'killed' : 'not-killed'}`, { error: `${stringifyError(event)}` });
Logger.error(`uncaughtException::gpu-process-crashed: ${killed ? 'killed' : 'not-killed'}`, { error: event });
});
};
3 changes: 1 addition & 2 deletions source/main/utils/processes.js
Expand Up @@ -2,7 +2,6 @@
import psList from 'ps-list';
import { isObject } from 'lodash';
import { Logger } from './logging';
import { stringifyError } from '../../common/utils/logging';

export type Process = {
pid: number,
Expand Down Expand Up @@ -48,7 +47,7 @@ export const getProcess = async (processId: number, processName: string): Promis
return previousProcess;
}
} catch (error) {
Logger.error('getProcess error', { error: `${stringifyError(error)}` });
Logger.error('getProcess error', { error });
return null;
}
};
5 changes: 2 additions & 3 deletions source/main/utils/rendererErrorHandler.js
Expand Up @@ -2,10 +2,9 @@
import { BrowserWindow } from 'electron';
import unhandled from 'electron-unhandled';
import { Logger } from './logging';
import { stringifyError } from '../../common/utils/logging';

unhandled({
logger: (error: any) => Logger.error('unhandledException::renderer', { error: `${stringifyError(error)}` }),
logger: (error: any) => Logger.error('unhandledException::renderer', { error }),
showDialog: false
});

Expand All @@ -21,7 +20,7 @@ export default class RendererErrorHandler {
}

onError(errorType: string, error: any) {
Logger.error(`RendererError::${errorType}`, { error: `${stringifyError(error)}` });
Logger.error(`RendererError::${errorType}`, { error });

if (this.count < this.maxReloads) {
this.count++;
Expand Down

0 comments on commit baf148c

Please sign in to comment.