diff --git a/src/contactMothership.js b/src/contactMothership.js index e6d5938b..cf5b8278 100644 --- a/src/contactMothership.js +++ b/src/contactMothership.js @@ -67,6 +67,9 @@ function post(bodyJson) { } ); + req.on('error', (e) => { + console.log(`ERROR: ${e.message}`); + }); req.write(bodyJson); req.end(); } diff --git a/src/errorHandling.ts b/src/errorHandling.ts index 372d160f..3082f419 100644 --- a/src/errorHandling.ts +++ b/src/errorHandling.ts @@ -23,7 +23,7 @@ function shouldNotStore(error: Error) { ); } -async function reportError(errorLogObj: ErrorLog) { +async function reportError(errorLogObj: ErrorLog, cb?: Function) { if (!errorLogObj.stack) { return; } @@ -34,10 +34,11 @@ async function reportError(errorLogObj: ErrorLog) { stack: errorLogObj.stack, more: JSON.stringify(errorLogObj.more ?? {}), }; - ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, JSON.stringify(body)); + await ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, JSON.stringify(body)); + cb?.(); } -function getToastProps(errorLogObj: ErrorLog) { +function getToastProps(errorLogObj: ErrorLog, cb?: Function) { const props = { message: t`Error: ` + errorLogObj.name, type: 'error', @@ -48,8 +49,8 @@ function getToastProps(errorLogObj: ErrorLog) { Object.assign(props, { actionText: t`Report Error`, action: () => { - reportError(errorLogObj); reportIssue(errorLogObj); + reportError(errorLogObj, cb); }, }); } @@ -60,7 +61,8 @@ function getToastProps(errorLogObj: ErrorLog) { export function handleError( shouldLog: boolean, error: Error, - more: object = {} + more: object = {}, + cb?: Function ) { if (shouldLog) { console.error(error); @@ -78,9 +80,9 @@ export function handleError( // @ts-ignore if (frappe.SystemSettings?.autoReportErrors) { - reportError(errorLogObj); + reportError(errorLogObj, cb); } else { - showToast(getToastProps(errorLogObj)); + showToast(getToastProps(errorLogObj, cb)); } } diff --git a/src/main.js b/src/main.js index 88d653bf..51756d15 100644 --- a/src/main.js +++ b/src/main.js @@ -74,10 +74,19 @@ import { stringifyCircular } from './utils'; console.error(err, vm, info); }; + window.onerror = (message, source, lineno, colno, error) => { + error = error ?? new Error('triggered in window.onerror'); + handleError(true, error, { message, source, lineno, colno }); + }; + process.on('unhandledRejection', (error) => { handleError(true, error); }); + process.on('uncaughtException', (error) => { + handleError(true, error, () => process.exit(1)); + }); + /* eslint-disable no-new */ new Vue({ el: '#app',