Skip to content
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

Add a filter option #18

Open
Coding-Kiwi opened this issue Apr 1, 2020 · 7 comments
Open

Add a filter option #18

Coding-Kiwi opened this issue Apr 1, 2020 · 7 comments

Comments

@Coding-Kiwi
Copy link

It would be great if we had a configurable filter function that, if defined in the options, gets called BEFORE the options.logger and showMessageBox function get called and returns true or false to decide if the error should pass or not.

That way one could filter out error messages like ERR_CONNECTION_REFUSED that are not catchable

@varunsrin
Copy link

@sindresorhus interested in working on this if you are open to it.

General idea is:

  • Add filter param to option, which should be a valid regex (defaults to undefined)
  • If filter !== undefined, the handleError method runs the regex over error.message
  • If it matches, handeError returns immediately, avoiding any logging or dialog displays

Anything I'm missing or additional features that you think are important? That seems similar to what was done here, so I wanted to double check that I'm not repeating a mistake.

@sindresorhus
Copy link
Owner

Add filter param to option, which should be a valid regex (defaults to undefined)

I think it should accept a RegExp or a function. If a function, the function would receive the error and return true/false for whether to keep it.

@Coding-Kiwi
Copy link
Author

I will never understand how opensource / pull requests is a thing that works. The time you guys spend on discussing this stupid little issue, the time you spend reviewing, rejecting and commenting the pull requests.. in all those hours and days spend, couldn't you just have implemented it yourself?

@sindresorhus
Copy link
Owner

sindresorhus commented Oct 9, 2021

@Coding-Kiwi Yes, it usually would have been faster for me to implement stuff myself, but, not everything is worth implementing. Whether someone is willing to do a pull request for a feature is a good indication of whether such feature is worth adding. Also, discussing the optimal solution is valuable. I often don't think of the best solution myself as I don't know all the requirements. I do implement important things myself when I have the time.

For example, in this situation. I have no need for this feature, but I'm willing to have it added if someone cares enough to do a good pull request.

Repository owner deleted a comment from TiagoSilvaPereira Oct 9, 2021
@varunsrin
Copy link

accepting a function makes sense, good suggestion. i now wonder if we should make it only a function to keep the interface simple. caller can wrap the regex into a function if they want to.

i will start working on it, and you can comment in the PR if you agree. easy modification either way.

@varunsrin
Copy link

@sindresorhus pr is here: #25

@sindresorhus
Copy link
Owner

If anyone wants to work on this, see the initial attempt in #25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants