nim-error-handling
Skill4 starsChanged 3 months agoMITView on GitHub
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.
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- planetis-m/skillsedited, first seen Jul 16, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- planetis-m/skills★ 5995% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository18 other files it gives its agents.
- atlas-package-clonerSkill
- buildSkill
- docs-genSkill
- format-codeSkill
- nim-api-designSkill
- nim-c-bindingsSkill
- nim-code-organizationSkill
- nim-c-wrappersSkill
- nim-debuggingSkill
- nim-defect-analysisSkill
- nim-doc-commentsSkill
- nim-fuzzingSkill
- nim-mcp-toolsSkill
- nimonypluginsSkill
- nim-ownership-hooksSkill
- nim-style-guideSkill
- nim-testingSkill
- run-testsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 5 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Use bool with a var parameter only when filling or mutating caller-owned storage is part of the API.
- Distinctive: line 19
Read what the current operation promises and how each called API reports failure.
- Distinctive: line 20
If a successful call guarantees valid output, do not add another raising nil, size, or range check.
- Distinctive: line 21
If a condition breaks no documented promise, remove the raising check and document the valid behavior.
- Distinctive: line 23
If an operation requires a stronger guarantee than the API it calls, validate that guarantee in that operation.
- Very specific: line 35
Put child exception types before their parents in except branches.
- Very specific: line 37
Add a custom exception only when callers handle it differently.
- Very specific: line 38
Do not use Defect for recoverable failures.
- Very specific: line 39
Use assert for conditions whose failure means a programming bug: preconditions, internal invariants, and state guards, as in assert …
- Very specific: line 41
Do not use range conversions for recoverable validation, e.g.
- Very specific: line 46
If the handler only needs the message text, use getCurrentExceptionMsg().
- Very specific: line 47
If the handler needs exception fields, use except X as e.
- Very specific: line 51
Use try/finally for cleanup.
- Very specific: line 52
Use {.raises: [].} when a proc must not raise.
- Distinctive: line 58
Place the decision: Document valid behavior as success, or report failure in the first operation whose promise is broken.
- Very specific: line 60
Enforce non-raising contracts: Add {.raises: [].} only to procs that must not raise.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Nim Error Handling
Rules
Choose the Failure Channel
- Return
boolwhen success or failure is the whole result. - Return
Option[T]when success returns a value but absence is expected. - Use
boolwith avarparameter only when filling or mutating caller-owned storage is part of the API. - Convert per-item failures into structured outcomes at the batch boundary. Keep intermediate steps exception-based.
Add Only Real Failure Paths
- Read what the current operation promises and how each called API reports failure.
- If a successful call guarantees valid output, do not add another raising nil, size, or range check.
- If a condition breaks no documented promise, remove the raising check and document the valid behavior.
- Report failure when the result cannot safely satisfy its API or the operation cannot meet its documented promise.
- If an operation requires a stronger guarantee than the API it calls, validate that guarantee in that operation.
Place Boundaries
- Let failures propagate through intermediate steps.
- Catch only where the handler can recover, translate, or record the failure.
- At a batch boundary, record recoverable per-item failures.
Choose Exception Types
- For a contract failure caused by caller input or the environment, raise the closest existing
CatchableError. - Separate
exceptbranches when handling differs. Group exception types when handling is identical. - Put child exception types before their parents in
exceptbranches. - Catch
CatchableErroronly when the boundary handles every recoverable error. Do not catch bareException. - Add a custom exception only when callers handle it differently. Derive it from the closest existing
CatchableErrorsubtype. - Do not use
Defectfor recoverable failures; it represents a programming bug and is not caught byCatchableError. - Use
assertfor conditions whose failure means a programming bug: preconditions, internal invariants, and state guards, as inassert s.opened, "next called before open". - Do not use range conversions for recoverable validation, e.g.
Positive(parseInt(s)); invalid values raiseRangeDefect.
Translate and Inspect Errors
- Translate errors only at module or subsystem boundaries. Add local context and preserve the original reason.
- If the handler only needs the message text, use
getCurrentExceptionMsg(). - If the handler needs exception fields, use
except X as e.
Cleanup and Contracts
- Use
try/finallyfor cleanup. - Use
{.raises: [].}when a proc must not raise. Leave raising procs unannotated.
Workflow
- Read the contracts. Note what this operation promises, how called APIs report failure, and what they guarantee on success.
- Decide whether failure is needed. Name the documented promise that the condition would break. If there is none, remove the check.
- Place the decision. Document valid behavior as success, or report failure in the first operation whose promise is broken.
- Place catch boundaries. Catch only where the handler can recover, translate, or record the failure.
- 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
references/batch_preview_boundary.md— Per-item batch failures with reporting failures allowed to escape.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

