openrewrite / rewrite-logging-frameworks

OpenRewrite recipes for assisting with Java logging migration tasks.
Apache License 2.0
25 stars 20 forks source link

Log exceptions swallowed in empty catch block #169

Open HelloDhero opened 2 months ago

HelloDhero commented 2 months ago

What problem are you trying to solve?

EmptyCatchBlock can bo auto fix

Describe the solution you'd like

when no throws or loggers in the catch statement, auto add loggers in catch

Have you considered any alternatives or workarounds?

Additional context

Are you interested in contributing this feature to OpenRewrite?

timtebeek commented 2 months ago

Hi @HelloDhero ; This seems a better fit for a new recipe in rewrite-logging-frameworks, as opposed to an extension to our EmptyBlock recipe. There would be a choice attached to what the user wants to happen here, as we would be changing semantics from swallowing all exceptions silently, to surfacing them somewhere.

A user might be using any from a number of loggers, might not have a field yet, which would then have to be added. As such an option for the logger implementation to choose would be a logical first step. Next we'd have to decide the log level for any exceptions swallowed, with perhaps a sensible default like debug, to prevent overwhelming the logs for previously silent handled paths.

These types of issues become apparent when you use our template to log a new recipe request, which is why that format is preferred. https://github.com/openrewrite/.github/blob/main/.github/ISSUE_TEMPLATE/recipe_request.md