Skip to content

Commit

Permalink
Add trap for unhandled exceptions (log to file, quit program)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsage committed Nov 15, 2022
1 parent b653f3c commit e15535a
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions modAssist_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,41 @@ const { ma_logger } = require('./lib/ma-logger.js')
const mcDetail = require('./package.json')
const semverGt = require('semver/functions/gt')
const log = new ma_logger('modAssist', app, 'assist.log', gotTheLock)
const path = require('path')
const fs = require('fs')

const devDebug = !(app.isPackaged)
const skipCache = false && !(app.isPackaged)
const crashLog = path.join(app.getPath('userData'), 'crash.log')
let updaterInterval = null

log.log.info(`ModAssist Logger: ${mcDetail.version}`)

process.on('uncaughtException', (err, origin) => {
fs.appendFileSync(
crashLog,
`Caught exception: ${err}\n\nException origin: ${origin}\n\n${err.stack}`
)
dialog.showMessageBoxSync(null, {
title : 'Uncaught Error - Quitting',
message : `Caught exception: ${err}\n\nException origin: ${origin}\n\n${err.stack}\n\n\nCan't Continue, exiting now!\n\nTo send file, please see ${crashLog}`,
type : 'error',
})
app.quit()
})
process.on('unhandledRejection', (err, origin) => {
fs.appendFileSync(
crashLog,
`Caught rejection: ${err}\n\nException origin: ${origin}\n\n${err.stack}`
)
dialog.showMessageBoxSync(null, {
title : 'Uncaught Error - Quitting',
message : `Caught rejection: ${err}\n\nException origin: ${origin}\n\n${err.stack}\n\n\nCan't Continue, exiting now!\n\nTo send file, please see ${crashLog}`,
type : 'error',
})
app.quit()
})

const translator = require('./lib/translate.js')
const myTranslator = new translator.translator(translator.getSystemLocale())
myTranslator.mcVersion = mcDetail.version
Expand Down Expand Up @@ -55,8 +83,6 @@ if ( process.platform === 'win32' && app.isPackaged && gotTheLock && !isPortable
updaterInterval = setInterval(() => { autoUpdater.checkForUpdatesAndNotify() }, ( 30 * 60 * 1000))
}

const path = require('path')
const fs = require('fs')
const glob = require('glob')
const fxml = require('fast-xml-parser')
const crypto = require('crypto')
Expand Down

0 comments on commit e15535a

Please sign in to comment.