linter icon indicating copy to clipboard operation
linter copied to clipboard

Make `avoid_catching_errors` more linient

Open goderbauer opened this issue 8 months ago • 5 comments

Issue https://github.com/dart-lang/linter/issues/3023 (dealing with avoid_catches_without_on_clauses) was also linked as a blocker for enabling the avoid_catching_errors lint in Flutter and when enabling it I am essentially running into the same classes of problems:

  • It flags when Errors are caught that are later rethrown after resetting some state.
  • It flags when Errors are caught to then throw a new Error with a more specific error message.
  • It flags when Errors 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 https://github.com/dart-lang/sdk/commit/500a8c0a72851ac95f60685e66df035246ca97c6 in response to https://github.com/dart-lang/linter/issues/3023 should also be applied to avoid_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 the avoid_catching_errors lint or whether just those specific categories mentioned above should be exempt from the lint.

goderbauer avatar Jun 17 '24 23:06 goderbauer