Find raw try/catch smells
ProprietarySearch-only bundle for try/catch shapes worth reviewing: collapse-to-null and collapse-to-default branches (candidates for runCatching { }.getOrNull() / .getOrDefault(...)), empty catches that lose every detail of the failure, broad catch (Exception) / catch (Throwable) clauses, catches that absorb the exception without logging or rethrowing, e.printStackTrace() calls that should be logger calls, nested try/catch trees, and catch parameters that are bound but never read.
org. openrewrite. kotlin. functional. FindTryCatchSmells$KtRecipemod run . --recipe= 'org. openrewrite. kotlin. functional. FindTryCatchSmells$KtRecipe'Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Find
try { x } catch (e: Exception) { null }patterns - Find
try { x } catch (e: Exception) { default }patterns - Find empty catch blocks
- Find broad
catch (e: Exception)/catch (e: Throwable)clauses - Find non-empty catch blocks that neither log nor rethrow
- Find
e.printStackTrace()calls inside a catch block - Find
try { } catch { }nested inside anothertry { } catch { } - Find
catch (e: Exception)clauses whose body never referencese