Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including electron-unhandled with all npm packages installed. Try it out:

var electronUnhandled = require("electron-unhandled")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

electron-unhandled v3.0.2

Catch unhandled errors and promise rejections in your Electron app

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 5 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

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free