Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/electron-unhandled
Catch unhandled errors and promise rejections in your Electron app
https://github.com/sindresorhus/electron-unhandled
electron electron-module
Last synced: 7 days ago
JSON representation
Catch unhandled errors and promise rejections in your Electron app
- Host: GitHub
- URL: https://github.com/sindresorhus/electron-unhandled
- Owner: sindresorhus
- License: mit
- Created: 2017-05-15T06:30:24.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-05-24T16:07:48.000Z (8 months ago)
- Last Synced: 2025-01-03T06:34:33.229Z (8 days ago)
- Topics: electron, electron-module
- Language: JavaScript
- Size: 27.3 KB
- Stars: 452
- Watchers: 7
- Forks: 26
- Open Issues: 9
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-github-star - electron-unhandled
- awesome-electron - electron-unhandled - Catch unhandled errors and promise rejections. (Tools / For Electron)
- awesome-electron - electron-unhandled - Catch unhandled errors and promise rejections. ![](https://img.shields.io/github/stars/sindresorhus/electron-unhandled.svg?style=social&label=Star) (Library / Uncategorized)
- awesome-electron-zh - electron-unhandled - Catch unhandled errors and promise rejections. (Tools / For Electron)
README
# electron-unhandled
> Catch unhandled errors and promise rejections in your [Electron](https://electronjs.org) app
You can use this module directly in both the main and renderer process.
## Install
```sh
npm install electron-unhandled
```*Requires Electron 30 or later.*
## Usage
```js
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](https://github.com/sindresorhus/electron-is-dev)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.
```js
import unhandled from 'electron-unhandled';
import {openNewGitHubIssue} from 'electron-util';
import {debugInfo} from 'electron-util/main';unhandled({
reportButton: error => {
openNewGitHubIssue({
user: 'sindresorhus',
repo: 'electron-unhandled',
body: `
## Node.js error stack\`\`\`
${stack}
\`\`\`## Node.js debug info
${debugInfo()}`
});
}
});
```[Example of how the GitHub issue will look like.](https://github.com/sindresorhus/electron-unhandled/issues/new?body=%60%60%60%0AError%3A+Test%0A++++at+%2FUsers%2Fsindresorhus%2Fdev%2Foss%2Felectron-unhandled%2Fexample.js%3A27%3A21%0A%60%60%60%0A%0A---%0A%0AExample+1.1.0%0AElectron+3.0.8%0Adarwin+18.2.0%0ALocale%3A+en-US)
### 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.
```js
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.
## Related
- [electron-store](https://github.com/sindresorhus/electron-store) - Save and load data like user settings, app state, cache, etc
- [electron-debug](https://github.com/sindresorhus/electron-debug) - Adds useful debug features to your Electron app
- [electron-context-menu](https://github.com/sindresorhus/electron-context-menu) - Context menu for your Electron app
- [electron-dl](https://github.com/sindresorhus/electron-dl) - Simplified file downloads for your Electron app