narrow-bare-rescue

Narrows bare Elixir rescue clauses to explicit exception types so programmer bugs propagate.

537|38|Updated Feb 12, 2026
One-click install
npx skills add https://github.com/oliver-kriska/claude-elixir-phoenix --skill narrow-bare-rescue
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: narrow-bare-rescue
Source: https://github.com/oliver-kriska/claude-elixir-phoenix/tree/main/targets/codex/skills/narrow-bare-rescue
Command: npx skills add https://github.com/oliver-kriska/claude-elixir-phoenix --skill narrow-bare-rescue

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Bare rescue _ -> clauses in Elixir swallow every exception, including UndefinedFunctionError from typos and KeyError from misspelled map keys, turning real bugs into silent {:error, :generic} fallbacks. This Skill audits those rescues and rewrites them to catch only the exception types the code path can actually raise.

Core Features & Use Cases

  • Rescue auditing: Finds bare rescue _ -> and rescue e -> sites across a single file, a directory, or the whole project, skipping already-typed rescues.
  • Verified exception taxonomy: Ships reference tables of exact exception types per work category (Jason, Ecto/Postgrex, Req, ExAws, ExCmd, Money/Decimal, Plug, LiveView HEEx, NimbleCSV), including gotchas like Phoenix.LiveView.Tokenizer.ParseError and internal NimbleCSV structs.
  • Refactoring patterns: Provides module-attribute hoisting for repeated rescue sets, Oban log-and-reraise with __STACKTRACE__, is_exception/1 replacements, large-cleanup partitioning, and a Credo check to prevent regressions.
  • Use Case: Run it on lib/my_app/ to convert every bare rescue into a typed list, then verify with mix compile --warnings-as-errors and the affected tests.

Quick Start

Ask the AI to audit and narrow all bare rescue clauses in lib/my_app/util/ using the narrow-bare-rescue skill, then compile and run the affected tests.

Frequently Asked Questions about narrow-bare-rescue

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix bare rescue clauses in Elixir?

Replace `rescue _ ->` with `rescue _ in [ExceptionType1, ExceptionType2] ->` listing only the exceptions the body can actually raise. Trace each call in the try or def body, consult a verified exception taxonomy, then run mix compile --warnings-as-errors to catch typos in module names.

Why is rescue _ -> dangerous in Elixir?

A bare rescue catches every exception, including programmer bugs like UndefinedFunctionError from typos and KeyError from misspelled map keys. The result is a silent fallback such as {:error, :generic} instead of a stack trace, hiding bugs from tests and error reporters.

Which exceptions should I rescue for Ecto and Postgrex?

Typical sets include Ecto.NoResultsError, Ecto.InvalidChangesetError, Ecto.ConstraintError, Ecto.StaleEntryError, Ecto.Query.CastError, Postgrex.Error, and DBConnection.ConnectionError. Add ArgumentError for bulk insert_all validation failures, and verify names with grep for defexception in deps.

Which exceptions should never appear in a narrowed rescue list?

Exclude UndefinedFunctionError, CompileError, BadFunctionError, and BadArityError because catching them hides programmer bugs that must propagate. FunctionClauseError and ArgumentError are exceptions only when raised as legitimate data signals, such as String.to_existing_atom on unknown input.

How do I log and reraise correctly in an Oban worker?

Narrow the rescue to the real failure types, log the message, then call reraise e, __STACKTRACE__ rather than reraise e, []. Preserving the original stack trace keeps Oban retry metadata and error reporters pointing at the true origin of the failure.

What are the limits of narrowing bare rescues?

The approach does not touch already-typed rescues, catch clauses for throws and exits, or replace try/rescue with with-based error tuples. It also must not be applied blindly, since dropping a genuinely raised exception is a behavioral regression.