-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
detect crashes and report them to Sentry
- Loading branch information
Showing
5 changed files
with
83 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters