Catch unhandled errors and promise rejections in your Electron app
You can use this module directly in both the main and renderer process.
$ npm install electron-unhandled
Requires Electron 7 or later.
const unhandled = require('electron-unhandled');
unhandled();
You probably want to call this both in the main
process and any renderer
processes to catch all possible errors.
Note: At minimum, this function must be called in the main
process
Type: object
Note: Options can only be specified in the main
process
Type: Function
Default: console.error
Custom logger that receives the error.
Can be useful if you for example integrate with Sentry.
Type: boolean
Default: Only in production
Present an error dialog to the user.
Type: Function
Default: undefined
When specified, the error dialog will include a Report…
button, which when clicked, executes the given function with the error as the first argument.
const unhandled = require('electron-unhandled');
const {openNewGitHubIssue, debugInfo} = require('electron-util');
unhandled({
reportButton: error => {
openNewGitHubIssue({
user: 'sindresorhus',
repo: 'electron-unhandled',
body: `\`\`\`\n${error.stack}\n\`\`\`\n\n---\n\n${debugInfo()}`
});
}
});
Example of how the GitHub issue will look like.
Log an error. This does the same as with caught unhandled errors.
It will use the same options specified in the unhandled()
call or the defaults.
Type: Error
Error to log.
Type: object
Type: string
Default: ${appName} encountered an error
Title of the error dialog.
- electron-store - Save and load data like user preferences, app state, cache, etc
- electron-debug - Adds useful debug features to your Electron app
- electron-context-menu - Context menu for your Electron app
- electron-dl - Simplified file downloads for your Electron app