Skip to main content

narrow-bare-rescue

Narrow bare rescue in Elixir so real errors like KeyError and typos propagate instead of being swallowed. Use to audit rescues and refactor error handling.

v1.0.0New

Unsigned, install at your own risk

Unverified

This skill has no cryptographic signature attached. We can't verify the contents match what the publisher intended.

Install this skill

No account required. Pick your tool, or use the command that detects it for you.

Run in your terminal. It detects your AI tool.

npx @skills-hub-ai/cli install elixir-phoenix-narrow-bare-rescue
Or get the file:
Browse all CLI commands →
Manual setup by platform

Claude Code

~/.claude/skills/elixir-phoenix-narrow-bare-rescue/SKILL.md

Setup guide →
0Save

Instructions

Narrow Bare Rescue

Turn rescue _ -> fallback into rescue _ in [ExceptionType1, ExceptionType2] -> fallback
so programmer bugs propagate while known failure modes stay handled.

Why this matters

Bare rescues (rescue _ ->, rescue e -> — any form without an in clause) swallow
every exception, including UndefinedFunctionError from typos, KeyError from
misspelled map keys, and CompileError from bad HEEx templates. The symptom isn't a stack
trace — it's a silent {:error, :generic} or a nil fallback. Bugs that should surface
in tests or error reporters become quiet degradations.

The Erlang Secure Coding Guide makes
the same case at the BEAM level — rule LNG-002 ("Do Not Use catch") warns that the
legacy catch-all form conflates normal returns, throws, and errors. Bare rescue in Elixir
is the direct analogue.

Iron Laws

  1. Never leave rescue _ -> or rescue e -> without an in clause. Every rescue must
    list exact exception types. The Credo check enforces this after cleanup lands.
  2. Cover every exception the code path can actually raise. Narrowing that drops a real
    exception is a behavioral regression — trace each call in the body before committing.
  3. Never include programmer-bug exceptions in the list. UndefinedFunctionError,
    CompileError, BadFunctionError, and BadArityError must propagate.
  4. Use reraise e, __STACKTRACE__, never reraise e, []. Preserve the original stack
    trace so Oban retry metadata and error reporters show the real origin.
  5. Run mix compile --warnings-as-errors before committing. Typos in exception module
    names only surface at compile time — the code looks fine until it loads.

The core transform

# Before — masks programmer bugs
def parse(body) do
  Jason.decode!(body)
rescue
  _ -> %{}
end

# After — catches only what can actually fail here
def parse(body) do
  Jason.decode!(body)
rescue
  _ in [Jason.DecodeError, ArgumentError] -> %{}
end

Applies identically to try … rescue … and to function-body def … rescue ….

Workflow

The skill operates in three modes depending on scope:

  1. Single file — /narrow-bare-rescue path/to/file.ex
  2. Directory — /narrow-bare-rescue lib/my_app/util/
  3. Whole project — /narrow-bare-rescue --all

Whatever the scope, follow this sequence.

Step 1 — Find the sites

grep -rn "^\s*rescue\s*$" <scope> | head -200

For each hit, read the 3 lines after to classify:

  • rescue _ -> or rescue var -> — bare, needs narrowing
  • rescue _ in [...] -> or rescue var in Something -> — already typed, skip
  • rescue ExceptionType -> (no variable binding) — already typed, skip

Step 2 — Determine the exception set for each bare site

Read the try / def body and trace what each call can raise. Don't guess from the
function name — verify. Consult order:

  1. Check ${CLAUDE_SKILL_DIR}/references/taxonomy.md for the work type (JSON, Ecto, Money, HTTP, etc.).
    Most sites map cleanly to one row.

  2. Grep deps for defexception when a specific library isn't in the taxonomy:

    grep -rn "defexception" deps/<libname>/lib/ | head -10
    
  3. Check raise calls in the code path itself — if the body explicitly raises
    RuntimeError, include it.

Priorities: cover everything the code can actually raise, exclude programmer-bug
exceptions (see Iron Law #3), and prefer specific types (Jason.DecodeError beats
ArgumentError if both could apply).

Step 3 — Apply the narrowing

For files with ≥3 rescues sharing a taxonomy, hoist to a module attribute — see
${CLAUDE_SKILL_DIR}/references/patterns.md for the module-attribute pattern, Oban reraise, ExCmd exit
errors, and is_exception/1 replacements.

Step 4 — Verify

After changes in each file (or cluster of files), run:

mix compile --warnings-as-errors
mix format <files_changed>
mix test <test_files_for_affected_modules>

The compile step catches typos in exception module names — a real risk since you're writing
module names from memory.

Scope

This skill narrows bare rescue clauses. It does not:

  • Auto-narrow blindly — behavior preservation matters; trace each call path first
  • Touch rescues that are already typed (rescue e in [X] ->) — those are correct
  • Cover catch clauses — throws and exits from the process are a separate concern
  • Replace try/rescue with with or error-tuple plumbing — that's a larger refactor

References

  • ${CLAUDE_SKILL_DIR}/references/taxonomy.md — verified exception types per work
    category, plus library-specific gotchas (NimbleCSV, Plug, Phoenix LiveView tokenizer)
  • ${CLAUDE_SKILL_DIR}/references/patterns.md — special patterns: is_exception/1,
    Oban reraise, ExCmd exit errors, module-attribute hoisting, partitioning large
    cleanups, the regression-prevention Credo check
  • Erlang Secure Coding Guide — LNG-002: Do Not Use catch
    — BEAM-level rationale for preferring narrow try ... catch / try ... rescue over
    the legacy catch-all form
This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

Browse all →

More from Elixir & Phoenix

View source →

More Build skills

Browse category →
senior-frontendBuild and review React, Next.js, TypeScript or Tailwind frontends: components, scaffolding, performance and bundle size. Use whenever the user wants a new component or app, a page feels slow, the bundle is too big, or asks for a frontend code review.635 installsui-design-systemUse when building a design system: tokens, component docs, responsive scales or developer handoff. Generates tokens with design_token_generator.py.535 installsfrontend-designGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.346 installssenior-backendBuild and fix backend services: REST or GraphQL APIs, auth, microservices, PostgreSQL queries, migrations and load tests. Use whenever the user's API is slow or broken, needs login or auth added, a schema change, or a new endpoint or service scaffolded.246 installsself-improving-agentCurate what the agent has learned into durable project knowledge. Reviews Claude Code auto-memory (MEMORY.md and its topic files) for learnings worth keeping, promotes proven ones into CLAUDE.md or .claude/rules/, records a correction as a lesson that persists across sessions, prunes stale or duplicate entries, and turns a recurring fix into a reusable skill. Use whenever the user asks what you have learned or saved about the project, which memories should become permanent rules, to remember a lesson or stop repeating a mistake, or to clean up, audit or check memory health.173 installsusing-superpowersUse when starting any conversation - establishes how to find and use skills, requiring skill invocation before ANY response including clarifying questions145 installs

Frequently asked questions about narrow-bare-rescue

What does the narrow-bare-rescue skill do?

Narrow bare rescue in Elixir so real errors like KeyError and typos propagate instead of being swallowed. Use to audit rescues and refactor error handling. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.

How do I install the narrow-bare-rescue skill?

Run `npx @skills-hub-ai/cli install elixir-phoenix-narrow-bare-rescue` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/elixir-phoenix-narrow-bare-rescue/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.

Which AI tools does narrow-bare-rescue work with?

narrow-bare-rescue runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.

Is the narrow-bare-rescue skill free?

Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.

How do I use narrow-bare-rescue after installing it?

In Claude Code, type `/elixir-phoenix-narrow-bare-rescue` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.

Can I share the narrow-bare-rescue skill with my team?

Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.