-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make avoid_catching_errors
more linient
#57128
Comments
avoid_catching_errors
more linientavoid_catching_errors
more linient
I'm in favor of keeping these consistent. I think the motivation behind each rule is similar in how |
Use
Shouldn't be necessary. Errors should not happen at all. (I can see how it can help debugging.) Frameworks can run unrelated and untrusted code as a component, and may want to handle errors for that component. Catching a specific error is still a bad idea. It's not OK that an error was thrown, it shouldn't be "handled".
That sounds like a framework boundary. Catch any thrown object (no
I'd say no. A catch-all at a framework boundary makes sense. Catching individual errors is against the intent of the |
That doesn't work for something like "count the number of Errors".
Debugging would be the main use case, yes. Debugging is one of the primary considerations of the Flutter framework. :-)
Sometimes you want to handle certain errors differently than others, e.g. Other examples where Flutter intentionally catches Errors: TextPainter catches an Some of those could be implemented differently, but I think it's a bit of an overgeneralization to say they're all bad ideas. |
The number of errors in production should be zero, so that should be easy 😉
That's a choice one can always make, but it is choosing to go directly against the lint intent. I'm not saying any these choices are inherently bad. I am saying that they should use I don't see a general enough rule that could be used as an exception, or enough uses that it's important to have one. |
Issue #58545 (dealing with
avoid_catches_without_on_clauses
) was also linked as a blocker for enabling theavoid_catching_errors
lint in Flutter and when enabling it I am essentially running into the same classes of problems:Error
s are caught that are laterrethrow
n after resetting some state.Error
s are caught to then throw a newError
with a more specific error message.Error
s are caught and directly passed to an error processing function (e.g.FlutterError.reportError
)I am wondering if the same lenience that was extended to
avoid_catches_without_on_clauses
in 500a8c0 in response to #58545 should also be applied toavoid_catching_errors
?FWIW, most of the uncovered reports of
avoid_catching_errors
are inside asserts to improve the debugging experience when those Errors happen during development. I wonder if catches in asserts should generally be exempt from theavoid_catching_errors
lint or whether just those specific categories mentioned above should be exempt from the lint.The text was updated successfully, but these errors were encountered: