Nim error handling

From planetis-m/skills · View interactive version

Nim error handling is an AI agent skill from the GitHub repository planetis-m/skills. Design clear Nim error-handling flows; when to raise exceptions vs return `Option`/`bool`, how to enforce non-raising contracts, and where to translate or record failures. Use when reviewing failure behavior, exception boundaries, recovery, or batch processing that needs per-item error reporting.

How to use this skill

Skill file

Nim Error Handling

Rules

Choose the Failure Channel

Add Only Real Failure Paths

Place Boundaries

Choose Exception Types

Translate Errors

Cleanup and Contracts

Workflow

  1. Read the contracts. Note what this operation promises, how called APIs report failure, and what they guarantee on success.
  2. Decide whether failure is needed. Name the documented promise that the condition would break. If there is none, remove the check.
  3. Place the decision. Document valid behavior as success, or report failure in the first operation whose promise is broken.
  4. Place catch boundaries. Catch only where the handler can recover, translate, or record the failure.
  5. Enforce non-raising contracts. Add {.raises: [].} only to procs that must not raise.

Common Mistakes

| Mistake | Why it is wrong |

|---------|-----------------|

| Parent except before child | First-match dispatch makes the child handler unreachable. |

| Catching bare Exception | Also catches Defect and can hide programming bugs. |

| Rechecking guaranteed output | Adds dead branches and can contradict the lower-level API. |

| Rejecting allowed behavior | Silently narrows the operation's contract. |

References

to escape.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.