mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 03:12:15 +00:00
feat(API): Report unhandled app crashes to Sentry (#4548)
* SIGTERM/SIGINT should only be handled once * move error-handling initialization to commands * create a new `sleep` function in workflow utils * detect crashes and report them to Sentry
This commit is contained in:
committed by
GitHub
parent
5d852f9230
commit
2425c10b2b
33
packages/cli/src/CrashJournal.ts
Normal file
33
packages/cli/src/CrashJournal.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { existsSync } from 'fs';
|
||||
import { mkdir, utimes, open, rm } from 'fs/promises';
|
||||
import { join, dirname } from 'path';
|
||||
import { UserSettings } from 'n8n-core';
|
||||
import { ErrorReporterProxy as ErrorReporter, LoggerProxy, sleep } from 'n8n-workflow';
|
||||
|
||||
export const touchFile = async (filePath: string): Promise<void> => {
|
||||
await mkdir(dirname(filePath), { recursive: true });
|
||||
const time = new Date();
|
||||
try {
|
||||
await utimes(filePath, time, time);
|
||||
} catch {
|
||||
const fd = await open(filePath, 'w');
|
||||
await fd.close();
|
||||
}
|
||||
};
|
||||
|
||||
const journalFile = join(UserSettings.getUserN8nFolderPath(), 'crash.journal');
|
||||
|
||||
export const init = async () => {
|
||||
if (existsSync(journalFile)) {
|
||||
// Crash detected
|
||||
ErrorReporter.warn('Last session crashed');
|
||||
LoggerProxy.error('Last session crashed');
|
||||
// add a 10 seconds pause to slow down crash-looping
|
||||
await sleep(10_000);
|
||||
}
|
||||
await touchFile(journalFile);
|
||||
};
|
||||
|
||||
export const cleanup = async () => {
|
||||
await rm(journalFile, { force: true });
|
||||
};
|
||||
Reference in New Issue
Block a user