mirror of
https://github.com/Eugeny/tabby.git
synced 2026-08-24 02:34:19 -05:00
catch import errors
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { app } from 'electron'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
// This module is imported before any other main-process module so that errors thrown
|
||||
// while importing those modules (which run before index.ts's own body) still get logged.
|
||||
|
||||
export function logMainError (label: string, err: unknown): void {
|
||||
const detail = err instanceof Error ? err.stack ?? err.message : String(err)
|
||||
const message = `[${new Date().toISOString()}] ${label}: ${detail}\n`
|
||||
process.stderr.write(message)
|
||||
try {
|
||||
const dir = process.env.TABBY_CONFIG_DIRECTORY ?? app.getPath('userData')
|
||||
fs.appendFileSync(path.join(dir, 'main-process-errors.log'), message)
|
||||
} catch { }
|
||||
}
|
||||
|
||||
process.on('uncaughtException', err => logMainError('uncaughtException', err))
|
||||
process.on('unhandledRejection', reason => logMainError('unhandledRejection', reason))
|
||||
+3
-15
@@ -1,6 +1,7 @@
|
||||
// Registers main-process error logging - must be first so it catches import-time errors
|
||||
import { logMainError } from './errors'
|
||||
|
||||
import { app, ipcMain, Menu, dialog } from 'electron'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
// set userData Path on portable version
|
||||
import './portable'
|
||||
@@ -19,14 +20,6 @@ import { Application } from './app'
|
||||
import electronDebug from 'electron-debug'
|
||||
import { loadConfig } from './config'
|
||||
|
||||
function logMainError (label: string, err: any): void {
|
||||
const message = `[${new Date().toISOString()}] ${label}: ${err?.stack ?? err}\n`
|
||||
process.stderr.write(message)
|
||||
try {
|
||||
fs.appendFileSync(path.join(process.env.TABBY_CONFIG_DIRECTORY!, 'main-process-errors.log'), message)
|
||||
} catch { }
|
||||
}
|
||||
|
||||
const argv = parseArgs(process.argv, process.cwd())
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/init-declarations
|
||||
@@ -57,14 +50,9 @@ ipcMain.on('app:new-window', () => {
|
||||
})
|
||||
|
||||
process.on('uncaughtException', err => {
|
||||
logMainError('uncaughtException', err)
|
||||
application.broadcast('uncaughtException', err)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', reason => {
|
||||
logMainError('unhandledRejection', reason)
|
||||
})
|
||||
|
||||
if (argv.d) {
|
||||
electronDebug({
|
||||
isEnabled: true,
|
||||
|
||||
Reference in New Issue
Block a user