-
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
avoid_catches_without_on_clauses
false positives
#58545
Comments
Forwarding to |
Another example of a false positive is |
Another false positive is when a new exception is thrown, wrapping the original one. |
Another false positive is when the |
How common are the false positive cases? Would it be better to fix them all, or to just stop using it? |
It did catch some problems, so it has value. flutter/flutter#91642 is the PR where I'm trying to turn it on (along with a few other lints), if you want to take a look. |
I wonder whether there's a better way to formulate the lint (something other than "don't do this broad thing except in these 5 cases"). Maybe one or more specific use cases that should unconditionally be avoided. |
The two problems I personally care about catching here are (1) cases where people willy-nilly swallow all exceptions because they just want to push all problems under the carpet, and (2) cases where someone wants to catch a specific exception but casts a much wider net than necessary (e.g. they just need to catch FormatException but they actually catch everything). Because Flutter is a framework it also does a lot of passing exceptions around, but I think that's pretty uncommon in apps. |
FWIW, due to the number of false positives, we've decided in flutter/flutter#91642 to disable the lint for Flutter's framework for now, but if we can ever enable it without all the //ignores I would be very happy because it catches some insidious patterns that a lot of people (including me) accidentally use and that are very hard to fix after the fact. |
This enables: - avoid_double_and_int_checks - avoid_js_rounded_ints - unsafe_html - use_setters_to_change_properties It also fixes a few places where the lints were violated. It does not enable `avoid_catches_without_on_clauses` or `avoid_catching_errors` but it does prepare us for a world where those lints have fewer false positives; see https://github.com/dart-lang/linter/issues/3023 for details.
This sounds like it would be hard to detect accurately. I think it may be hard to invert the rule's logic to target this case. On the other hand, might not be to hard to just make some allowances for the above exceptions like:
|
That sounds reasonable to me. We might also consider adding
|
Ooh good thought. I can add that one. |
My only note would be that instead of hard-coding |
It would take years to get that annotation into |
Fixes https://github.com/dart-lang/linter/issues/3023 This fix is a little unusually large because I have to add some elements to both the mock flutter package, and the mock SDK. This affects some completion tests. Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try Change-Id: I44b68754f756cfe1cf99518957d74c4af56043f1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368260 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
Fixed with 500a8c0 |
This bug was also linked as a blocker for enabling the
I am wondering if the same lenience that was extended to FWIW, most of the uncovered reports of |
One valid use for catching all exceptions and errors is to forward them to some error reporting logic, for example, the way that Flutter frequently catches all exceptions and forwards them to
FlutterError.reportError
.It would be nice if a function like
FlutterError.reportError
could be annotated as a valid reason to catch exceptions, such that if thecatch
block contains a call to such a function, it isn't flagged withavoid_catches_without_on_clauses
.The text was updated successfully, but these errors were encountered: