Catch unhandled errors and promise rejections in your Electron app
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Init May 15, 2017
.gitattributes Meta tweaks Oct 30, 2018
.gitignore Meta tweaks Dec 15, 2017
.npmrc Meta tweaks Dec 15, 2017
.travis.yml Meta tweaks Oct 30, 2018
example.js Add `title` option to `unhandled.logError()` Nov 11, 2018
fixture-error.js Require Electron 3 Oct 30, 2018
fixture-rejection.js Require Electron 3 Oct 30, 2018
index.js Add `title` option to `unhandled.logError()` Nov 11, 2018
license Meta tweaks Dec 15, 2017
package.json 2.1.0 Nov 11, 2018
readme.md Add `title` option to `unhandled.logError()` Nov 11, 2018
screenshot.png Init May 15, 2017
test.js Init May 15, 2017

readme.md

electron-unhandled Build Status

Catch unhandled errors and promise rejections in your Electron app

You can use this module directly in both the main and renderer process.

Install

$ npm install electron-unhandled

Requires Electron 3 or later.

Usage

const unhandled = require('electron-unhandled');

unhandled();

API

unhandled([options])

You probably want to call this both in the main process and any renderer processes to catch all possible errors.

options

Type: Object

logger

Type: Function
Default: console.error

Custom logger that receives the error.

Can be useful if you for example integrate with Sentry.

showDialog

Type: boolean
Default: Only in production

Present an error dialog to the user.

reportButton

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.

unhandled.logError(error, [options])

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.

error

Type: Error

Error to log.

options

Type: Object

title

Type: string
Default: ${appName} encountered an error

Title of the error dialog.

Related

License

MIT © Sindre Sorhus