mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 14:39:06 +00:00
feat: generate crash report (#787)
This commit is contained in:
@@ -45,6 +45,7 @@ import { populateDemo } from './modules/loadDemo.js';
|
|||||||
import { getState, updateRundownData } from './stores/runtimeState.js';
|
import { getState, updateRundownData } from './stores/runtimeState.js';
|
||||||
import { setRundown } from './services/rundown-service/RundownService.js';
|
import { setRundown } from './services/rundown-service/RundownService.js';
|
||||||
import { getPlayableEvents } from './services/rundown-service/rundownUtils.js';
|
import { getPlayableEvents } from './services/rundown-service/rundownUtils.js';
|
||||||
|
import { generateCrashReport } from './utils/generateCrashReport.js';
|
||||||
|
|
||||||
console.log(`Starting Ontime version ${ONTIME_VERSION}`);
|
console.log(`Starting Ontime version ${ONTIME_VERSION}`);
|
||||||
|
|
||||||
@@ -286,12 +287,14 @@ process.on('exit', (code) => console.log(`Ontime shutdown with code: ${code}`));
|
|||||||
|
|
||||||
process.on('unhandledRejection', async (error) => {
|
process.on('unhandledRejection', async (error) => {
|
||||||
console.error('Error: unhandled rejection', error);
|
console.error('Error: unhandled rejection', error);
|
||||||
|
generateCrashReport(error);
|
||||||
logger.error(LogOrigin.Server, `Error: unhandled rejection ${error}`);
|
logger.error(LogOrigin.Server, `Error: unhandled rejection ${error}`);
|
||||||
await shutdown(1);
|
await shutdown(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('uncaughtException', async (error) => {
|
process.on('uncaughtException', async (error) => {
|
||||||
console.error('Error: uncaught exception', error);
|
console.error('Error: uncaught exception', error);
|
||||||
|
generateCrashReport(error);
|
||||||
logger.error(LogOrigin.Server, `Error: uncaught exception ${error}`);
|
logger.error(LogOrigin.Server, `Error: uncaught exception ${error}`);
|
||||||
await shutdown(1);
|
await shutdown(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -123,3 +123,6 @@ export const pathToStartDemo = config.demo.filename.map((file) => {
|
|||||||
|
|
||||||
// path to restore file
|
// path to restore file
|
||||||
export const resolveRestoreFile = join(getAppDataPath(), config.restoreFile);
|
export const resolveRestoreFile = join(getAppDataPath(), config.restoreFile);
|
||||||
|
|
||||||
|
// path to crash reports
|
||||||
|
export const resolveCrashReportDirectory = getAppDataPath();
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import { writeFileSync } from 'fs';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
|
import { ONTIME_VERSION } from '../ONTIME_VERSION.js';
|
||||||
|
import { get } from '../services/rundown-service/rundownCache.js';
|
||||||
|
import { getState } from '../stores/runtimeState.js';
|
||||||
|
import { resolveCrashReportDirectory } from '../setup.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a file to the crash report location
|
||||||
|
* @param fileName
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
function writeToFile(fileName: string, content: object) {
|
||||||
|
const path = join(resolveCrashReportDirectory, fileName);
|
||||||
|
try {
|
||||||
|
const textContent = JSON.stringify(content, null, 2);
|
||||||
|
writeFileSync(path, textContent);
|
||||||
|
} catch (e_rror) {
|
||||||
|
/** We do not handle the error here */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generates a crash report
|
||||||
|
* @param error
|
||||||
|
*/
|
||||||
|
export function generateCrashReport(maybeError: unknown) {
|
||||||
|
const timeNow = new Date().toISOString();
|
||||||
|
const runtimeState = getState();
|
||||||
|
const rundownState = get();
|
||||||
|
const error =
|
||||||
|
maybeError instanceof Error
|
||||||
|
? {
|
||||||
|
message: maybeError.message,
|
||||||
|
stack: maybeError.stack || 'No stack trace available',
|
||||||
|
}
|
||||||
|
: String(maybeError);
|
||||||
|
|
||||||
|
const crashReport = {
|
||||||
|
time: timeNow,
|
||||||
|
version: ONTIME_VERSION,
|
||||||
|
error,
|
||||||
|
runtimeState,
|
||||||
|
rundownState,
|
||||||
|
};
|
||||||
|
|
||||||
|
writeToFile(`crash-log-${timeNow}.log`, crashReport);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user