-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added patch for filter option in electron-unhandled #268
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
diff --git a/node_modules/electron-unhandled/index.d.ts b/node_modules/electron-unhandled/index.d.ts | ||
index 6231ad4..b5172f2 100644 | ||
--- a/node_modules/electron-unhandled/index.d.ts | ||
+++ b/node_modules/electron-unhandled/index.d.ts | ||
@@ -1,31 +1,33 @@ | ||
-declare namespace unhandled { | ||
+ declare namespace unhandled { | ||
interface 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. | ||
+ Filter option that receives an array of regex. | ||
+ electron-unhandled would not show the error dialog if error message passed by any of regex. | ||
+ @default [] | ||
+ */ | ||
+ readonly filter?: Array<RegExp>; | ||
|
||
+ /** | ||
+ 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 = require('electron-unhandled'); | ||
import {openNewGitHubIssue, debugInfo} = require('electron-util'); | ||
- | ||
unhandled({ | ||
reportButton: error => { | ||
openNewGitHubIssue({ | ||
@@ -35,7 +37,6 @@ declare namespace unhandled { | ||
}); | ||
} | ||
}); | ||
- | ||
// 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 | ||
``` | ||
*/ | ||
@@ -45,7 +46,6 @@ declare namespace unhandled { | ||
interface LogErrorOptions { | ||
/** | ||
Title of the error dialog. | ||
- | ||
@default `${appName} encountered an error` | ||
*/ | ||
readonly title?: string; | ||
@@ -55,19 +55,16 @@ declare namespace unhandled { | ||
declare const unhandled: { | ||
/** | ||
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. | ||
*/ | ||
(options?: unhandled.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 - Error to log. | ||
*/ | ||
logError(error: Error, options?: unhandled.LogErrorOptions): void; | ||
}; | ||
|
||
-export = unhandled; | ||
+export = unhandled | ||
\ No newline at end of file | ||
diff --git a/node_modules/electron-unhandled/index.js b/node_modules/electron-unhandled/index.js | ||
index 094955d..7ea7ed9 100644 | ||
--- a/node_modules/electron-unhandled/index.js | ||
+++ b/node_modules/electron-unhandled/index.js | ||
@@ -17,11 +17,15 @@ let installed = false; | ||
|
||
let options = { | ||
logger: console.error, | ||
- showDialog: !isDev | ||
+ showDialog: !isDev, | ||
+ filter: [] | ||
}; | ||
|
||
const handleError = (title, error) => { | ||
error = ensureError(error); | ||
+ if (options.filter && options.filter.some(regex => regex.test(error.message))) { | ||
+ return; | ||
+ } | ||
|
||
try { | ||
options.logger(error); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these added here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added typescript type for
filter
in index.t.ds