-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.d.ts
79 lines (60 loc) · 2.16 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
__Note:__ Options can only be specified in the `main` process.
*/
export type UnhandledOptions = {
/**
Custom logger that receives the error.
Can be useful if you for example integrate with Sentry.
@default console.error
*/
readonly logger?: (error: Error) => void;
/**
Present an error dialog to the user.
Default: [Only in production](https://github.com/sindresorhus/electron-is-dev).
*/
readonly showDialog?: boolean;
/**
When specified, the error dialog will include a `Report…` button, which when clicked, executes the given function with the error as the first argument.
@default undefined
@example
```
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: 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
```
*/
readonly reportButton?: (error: Error) => void;
};
export type LogErrorOptions = {
/**
The title of the error dialog.
@default `${appName} encountered an error`
*/
readonly title?: string;
};
/**
Catch unhandled errors and promise rejections in your [Electron](https://electronjs.org) app.
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.
*/
export default function unhandled(options?: UnhandledOptions): void;
/**
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.
@param error - The error to log.
@example
```
import {logError} from 'electron-unhandled';
logError(new Error('🦄'));
```
*/
export function logError(error: Error, options?: LogErrorOptions): void;