Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add original stacktrace to error handling
- Loading branch information
1 parent
300caf0
commit c893fe9
Showing
2 changed files
with
20 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,44 @@ | ||
const WAIT_FOR_WIN_TIMEOUT_DURATION = 5000; | ||
const WAIT_FOR_WIN_TIMEOUT_DURATION = 4000; | ||
const ERROR_EV = 'ELECTRON_ERROR'; | ||
const mainWinMod = require('./main-window'); | ||
|
||
module.exports = (e = 'UNDEFINED ERROR', additionalLogInfo) => { | ||
if (isReadyForFrontEndError()) { | ||
handleError(e, additionalLogInfo); | ||
const errObj = new Error(e); | ||
|
||
if (_isReadyForFrontEndError()) { | ||
_handleError(e, additionalLogInfo, errObj); | ||
} else { | ||
// try again a little later, when window might be ready | ||
setTimeout(() => { | ||
handleError(e, additionalLogInfo); | ||
_handleError(e, additionalLogInfo, errObj); | ||
}, WAIT_FOR_WIN_TIMEOUT_DURATION); | ||
} | ||
}; | ||
|
||
function isReadyForFrontEndError() { | ||
function _isReadyForFrontEndError() { | ||
const mainWin = mainWinMod.getWin(); | ||
const isAppReady = mainWinMod.getIsAppReady(); | ||
return mainWin && mainWin.webContents && isAppReady; | ||
} | ||
|
||
function handleError(e, additionalLogInfo) { | ||
function _handleError(e, additionalLogInfo, errObj) { | ||
const mainWin = mainWinMod.getWin(); | ||
const stack = errObj.stack; | ||
|
||
console.error('ERR', e); | ||
console.log(stack); | ||
|
||
if (additionalLogInfo) { | ||
console.log('Additional Error info: ', additionalLogInfo); | ||
} | ||
|
||
if (isReadyForFrontEndError()) { | ||
mainWin.webContents.send(ERROR_EV, e); | ||
if (_isReadyForFrontEndError()) { | ||
mainWin.webContents.send(ERROR_EV, { | ||
error: e, | ||
stack: stack, | ||
}); | ||
} else { | ||
console.error('ERR', 'Frontend not loaded'); | ||
throw new Error(e) | ||
throw errObj; | ||
} | ||
} |