Skip to content

Commit d9cce3c

Browse files
committed
chore: moved crash reporter logic to a separate folder
1 parent 1f69c6b commit d9cce3c

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

ts/mains/main_node.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from 'electron';
2222

2323
import crypto from 'crypto';
24-
import fs, { appendFileSync } from 'fs';
24+
import fs from 'fs';
2525
import os from 'os';
2626
import path, { join } from 'path';
2727
import { platform as osPlatform } from 'process';
@@ -153,8 +153,23 @@ if (!process.mas) {
153153
}
154154
}
155155

156+
/**
157+
* Starts the crash reporter, which saves crashes to disk.
158+
* The dumps will be saved in the `userData/CrashPad/pending` directory.
159+
*
160+
* The minidumps can be read using the `minidump_stackwalk` tool.
161+
* If you do not have cargo installed, you can do those steps:
162+
* ```bash
163+
* git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
164+
* cd depot_tools
165+
* mkdir breakpad && cd breakpad
166+
* ../fetch breakpad && cd src
167+
* ./configure && make
168+
* file src/processor/minidump_stackwalk
169+
* ./src/processor/minidump_stackwalk <path_to.dmp> <any_symbols_you_have_optional>
170+
*/
156171
crashReporter.start({
157-
submitURL: '', // leave empty if you dont want to upload
172+
submitURL: '', // leave empty as we don't want to upload them, but only save them locally
158173
uploadToServer: false,
159174
compress: true,
160175
});
@@ -185,6 +200,8 @@ import * as log from '../util/logger/log';
185200
import { DURATION } from '../session/constants';
186201
import { tr } from '../localization/localeTools';
187202

203+
import { logCrash } from '../node/crash/log_crash';
204+
188205
function prepareURL(pathSegments: Array<string>, moreKeys?: { theme: any }) {
189206
const urlObject: url.UrlObject = {
190207
pathname: join(...pathSegments),
@@ -367,11 +384,6 @@ async function createWindow() {
367384
mainWindow.on('focus', setWindowFocus);
368385
mainWindow.on('blur', setWindowFocus);
369386
mainWindow.once('ready-to-show', setWindowFocus);
370-
function logCrash(type: string, details: any) {
371-
const crashLogPath = path.join(app.getPath('userData'), 'crash-log.txt');
372-
const logLine = `[${new Date().toISOString()}] ${type} crash: ${JSON.stringify(details)}\n`;
373-
appendFileSync(crashLogPath, logLine, 'utf8');
374-
}
375387

376388
mainWindow.webContents.on('render-process-gone', (_event, details) => {
377389
// details.reason can be: 'crashed', 'killed', 'oom', etc.

ts/node/crash/log_crash.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { app } from 'electron';
2+
import { appendFileSync } from 'fs-extra';
3+
import path from 'node:path';
4+
5+
/**
6+
* Logs a crash of the renderer/main process to the userData directory, file `crash-log.txt`.
7+
* Also, see the crashReporter for dumps of the crash itself
8+
*/
9+
export function logCrash(type: string, details: any) {
10+
const crashLogPath = path.join(app.getPath('userData'), 'crash-log.txt');
11+
const logLine = `[${new Date().toISOString()}] ${type} crash: ${JSON.stringify(details)}\n`;
12+
appendFileSync(crashLogPath, logLine, 'utf8');
13+
}

ts/node/global_errors.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
import path from 'node:path';
2-
import { appendFileSync } from 'node:fs';
31
import { app, dialog, clipboard } from 'electron';
42
import os from 'node:os';
53
import { reallyJsonStringify } from '../util/reallyJsonStringify';
64
import { Errors } from '../types/Errors';
75
import { redactAll } from '../util/privacy';
6+
import { logCrash } from './crash/log_crash';
87

98
// TODO: use localised strings
109
const quitText = 'Quit';
1110
const copyErrorAndQuitText = 'Copy error and quit';
1211

13-
function logCrash(type: string, details: any) {
14-
const crashLogPath = path.join(app.getPath('userData'), 'crash-log.txt');
15-
const logLine = `[${new Date().toISOString()}] ${type} crash: ${JSON.stringify(details)}\n`;
16-
appendFileSync(crashLogPath, logLine, 'utf8');
17-
}
18-
1912
function handleError(prefix: string, error: Error): void {
2013
const formattedError = Errors.toString(error);
2114
if (console._error) {

0 commit comments

Comments
 (0)