added an easy comment for call-stacks in the _queryServer logs
This commit is contained in:
parent
04921d2b1c
commit
9a17a1d97f
@ -3,6 +3,8 @@ const electronConsole = electronRemote.getGlobal('console') as Console;
|
|||||||
import Logger from '../../logger/logger';
|
import Logger from '../../logger/logger';
|
||||||
const LOG = Logger.create(__filename, electronConsole);
|
const LOG = Logger.create(__filename, electronConsole);
|
||||||
|
|
||||||
|
import * as StackTrace from '../../stack-trace/stack-trace';
|
||||||
|
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
@ -359,7 +361,9 @@ export default class ClientController extends EventEmitter {
|
|||||||
async _queryServer(endpoint: string, ...args: any[]): Promise<any> {
|
async _queryServer(endpoint: string, ...args: any[]): Promise<any> {
|
||||||
// NOTE: socket.io may cause client-side memory leaks if the ack function is never called
|
// NOTE: socket.io may cause client-side memory leaks if the ack function is never called
|
||||||
await this.ensureVerified(5000);
|
await this.ensureVerified(5000);
|
||||||
LOG.silly('querying s#' + this.id + ' @' + endpoint + ' / [' + args.map(arg => LOG.inspect(arg)).join(', ') + ']');
|
let message = `querying s#${this.id} @${endpoint}(${args.map(arg => LOG.inspect(arg)).join(', ')})`;
|
||||||
|
LOG.silly(message);
|
||||||
|
//if (endpoint === 'fetch-messages-recent') LOG.silly(null, new Error('call stack'));
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
this._socketEmitTimeout(5000, endpoint, ...args, async (errMsg: string, serverData: any) => {
|
this._socketEmitTimeout(5000, endpoint, ...args, async (errMsg: string, serverData: any) => {
|
||||||
if (errMsg) {
|
if (errMsg) {
|
||||||
|
@ -11,6 +11,8 @@ import * as StackTrace from '../stack-trace/stack-trace';
|
|||||||
const LINE_NUM_LENGTH = 3;
|
const LINE_NUM_LENGTH = 3;
|
||||||
const MAX_FILE_NAME_PADDING = 22;
|
const MAX_FILE_NAME_PADDING = 22;
|
||||||
|
|
||||||
|
const baseDir = path.join(__dirname, '..', '..');
|
||||||
|
|
||||||
/** Adds padding to the left of a string */
|
/** Adds padding to the left of a string */
|
||||||
function padLeft(string: string, padding: string, minLength: number) {
|
function padLeft(string: string, padding: string, minLength: number) {
|
||||||
while (string.length < minLength) {
|
while (string.length < minLength) {
|
||||||
@ -183,6 +185,13 @@ export default class Logger {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getTSStackFrames(err: Error): StackTrace.Frame[] {
|
||||||
|
let jsFrames: StackTrace.Frame[] = StackTrace.parse(err);
|
||||||
|
let tsFrames = jsFrames.map(jsFrame => tryCreateTSFrame(this.sourceMaps, jsFrame));
|
||||||
|
tsFrames = tsFrames.map(tsFrame => StackTrace.relativizeFilePath(tsFrame, baseDir));
|
||||||
|
return tsFrames;
|
||||||
|
}
|
||||||
|
|
||||||
/** Logs a message and potentially corresponding data */
|
/** Logs a message and potentially corresponding data */
|
||||||
private log(level: LoggerLevel, message: string | null, data?: Error | any): void {
|
private log(level: LoggerLevel, message: string | null, data?: Error | any): void {
|
||||||
let frames: StackTrace.Frame[] = StackTrace.parse(new Error());
|
let frames: StackTrace.Frame[] = StackTrace.parse(new Error());
|
||||||
@ -216,11 +225,8 @@ export default class Logger {
|
|||||||
}
|
}
|
||||||
if (data instanceof Error) {
|
if (data instanceof Error) {
|
||||||
if (data.stack) {
|
if (data.stack) {
|
||||||
const baseDir = path.join(__dirname, '..', '..');
|
let errorFrames = this.getTSStackFrames(data);
|
||||||
let errorFrames = StackTrace.parse(data);
|
|
||||||
let tsStackLines = errorFrames
|
let tsStackLines = errorFrames
|
||||||
.map((frame: StackTrace.Frame) => tryCreateTSFrame(this.sourceMaps, frame))
|
|
||||||
.map((frame: StackTrace.Frame) => StackTrace.relativizeFilePath(frame, baseDir))
|
|
||||||
.map((frame: StackTrace.Frame) => StackTrace.getFrameLine(frame));
|
.map((frame: StackTrace.Frame) => StackTrace.getFrameLine(frame));
|
||||||
out += `${prefix}# ${data.name}: ${data.message}`;
|
out += `${prefix}# ${data.name}: ${data.message}`;
|
||||||
out += `\n${prefix}# ${tsStackLines.join(`\n${prefix}# `)}`;
|
out += `\n${prefix}# ${tsStackLines.join(`\n${prefix}# `)}`;
|
||||||
|
@ -15,7 +15,7 @@ export function parse(err: Error): Frame[] {
|
|||||||
|
|
||||||
const lines = err.stack.split('\n').slice(1);
|
const lines = err.stack.split('\n').slice(1);
|
||||||
return lines
|
return lines
|
||||||
.map(function(line: string): Frame | null {
|
.map(function(line: string): Frame {
|
||||||
if (line.match(/^\s*[-]{4,}$/)) {
|
if (line.match(/^\s*[-]{4,}$/)) {
|
||||||
return { fileName: line };
|
return { fileName: line };
|
||||||
}
|
}
|
||||||
@ -36,10 +36,7 @@ export function parse(err: Error): Frame[] {
|
|||||||
// chop of parenthesis chop off 'at' and file path
|
// chop of parenthesis chop off 'at' and file path
|
||||||
return parseData(pieces[pieces.length - 1].slice(1, -1), pieces.slice(1, -1).join(' '));
|
return parseData(pieces[pieces.length - 1].slice(1, -1), pieces.slice(1, -1).join(' '));
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
.filter(function(callSite): boolean {
|
|
||||||
return !!callSite;
|
|
||||||
}) as Frame[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function relativizeFilePath(frame: Frame, baseDir: string): Frame {
|
export function relativizeFilePath(frame: Frame, baseDir: string): Frame {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES6",
|
"target": "ES2017",
|
||||||
"module": "CommonJS",
|
"module": "CommonJS",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
|
Loading…
Reference in New Issue
Block a user