Socket
Socket
Sign inDemoInstall

electron-unhandled

Package Overview
Dependencies
7
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    electron-unhandled

Catch unhandled errors and promise rejections in your Electron app


Version published
Weekly downloads
6.2K
decreased by-14.91%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

electron-unhandled

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 30 or later.

Usage

import unhandled from '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.

Note: At minimum, this function must be called in the main process.

options

Type: object

Note: Options can only be specified in the main process.

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.

import unhandled from 'electron-unhandled';
import {openNewGitHubIssue, debugInfo} from '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.

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.

import {logError} from 'electron-unhandled';

logError(new Error('🦄'));
error

Type: Error

The error to log.

options

Type: object

title

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

The title of the error dialog.

Keywords

FAQs

Last updated on 01 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc