Log unhandled errors and promise rejections in the desktop app
Test code: setTimeout(() => testFunctionSync(), 5000); setTimeout( () => testFunction().then(() => console.log("done testFunction")), 10000, ); const testFunctionSync = () => { console.log("sleeping not"); throw new Error("Handle me"); }; const testFunction = async () => { console.log("sleeping"); await fs.mkdir("/tmp/foo", { recursive: true }); console.log("woke up"); throw new Error("Handle me"); };
This commit is contained in:
parent
5eda8fd464
commit
6ec4cc7c89
1 changed files with 10 additions and 0 deletions
|
@ -19,6 +19,16 @@ export const initLogging = () => {
|
|||
log.transports.file.format = "[{y}-{m}-{d}T{h}:{i}:{s}{z}] {text}";
|
||||
|
||||
log.transports.console.level = false;
|
||||
|
||||
// Log unhandled errors and promise rejections.
|
||||
log.errorHandler.startCatching({
|
||||
onError: ({ error, errorName }) => {
|
||||
logError(errorName, error);
|
||||
// Prevent the default electron-log actions (e.g. showing a dialog)
|
||||
// from getting triggered.
|
||||
return false;
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue