fsharp-failure-paths
Skill23 starsChanged 32 days agoMITView on GitHub
Make failures in F# code explicit instead of crashing or hiding them. Use when writing or reviewing F# that calls partial functions (List.head, Seq.find, Map.find, .Value), uses failwith, falls back with defaultArg or Option.defaultValue, catches exceptions, or combines several validations into one Result.
In this repository16 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- fsharp-async-compositionSkill
- fsharp-binary-compatibilitySkill
- fsharp-env-capabilitiesSkill
- fsharp-idiom-reviewSkill
- fsharp-iwsam-errorsSkill
- fsharp-library-api-designSkill
- fsharp-native-aotSkill
- fsharp-nullness-interopSkill
- fsharp-performance-typesSkill
- fsharp-serializationSkill
- fsharp-signature-filesSkill
- fsharp-verify-apiSkill
- optimize-fsharp-typecheck-graphSkill
- parse-dont-validateSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 4 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 18
Do not call a partial function on a value that the type lets be empty or absent.
- Very specific: line 19
Use the safe form and handle each case: List.tryHead, Seq.tryFind, Map.tryFind, Option pattern match.
- Very specific: line 21
Use failwith and invalidArg only for a broken invariant that the caller cannot cause or recover from.
- Very specific: line 22
When input, configuration, or a dependency can cause the failure, return Error.
- Very specific: line 23
Use defaultArg and Option.defaultValue only when the contract defines the default.
- Distinctive: line 24
When the value is required, report the absence.
- Very specific: line 25
Do not catch every exception and return empty data.
- Very specific: line 27
When several checks validate independent inputs, return every error.
- Very specific: line 28
Use validation from FsToolkit.ErrorHandling, or collect the Error cases into a list.
- Distinctive: line 29
Check each guard helper with a true and a false condition.
- Distinctive: line 31
Read references/PATTERNS.md for each pattern with its unsafe form and its safe form.
- Very specific: line 39
Run the code with each failing input from step 2.
- Distinctive: line 43
Run the proof script from the skill root:
≈ “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
F# failure paths
The compiler accepts code that crashes on an empty list or hides a missing value. Human reviewers find these defects, so the agent must find them first. Review evidence ranks failure-path handling as a top category of human comments on agent F# code.
Model input boundaries with parse-dont-validate. This skill covers what happens after a call can fail.
Rules
- Do not call a partial function on a value that the type lets be empty or absent.
Use the safe form and handle each case:
List.tryHead,Seq.tryFind,Map.tryFind,Optionpattern match. A pattern match such asfirst :: _is safe when the empty case also has a branch. - Use
failwithandinvalidArgonly for a broken invariant that the caller cannot cause or recover from. When input, configuration, or a dependency can cause the failure, returnError. - Use
defaultArgandOption.defaultValueonly when the contract defines the default. When the value is required, report the absence. A default for a removed setting hides the removal and keeps stale behavior. - Do not catch every exception and return empty data. A later step then reports the wrong cause, or reports success.
Catch the exceptions that you expect, and keep the cause in the error:
with ex -> Error(RatesUnavailable ex). - When several checks validate independent inputs, return every error.
List.head errorsandResult.bindchains stop at the first error. Usevalidationfrom FsToolkit.ErrorHandling, or collect theErrorcases into a list. - Check each guard helper with a true and a false condition. A reversed condition compiles and rejects valid input.
Read references/PATTERNS.md for each pattern with its unsafe form and its safe form.
Steps
- List every partial function,
failwith,defaultArg,Option.defaultValue,try ... with, and first-error-only path in the change. Done when each item is on the list. - For each item, name the input that makes it fail: empty collection, missing key, missing setting, failed dependency, or a second invalid value.
- Change each item that the input can reach to return
Errorwith the cause. Keep eachfailwithonly for a broken invariant, and keep each default only when the contract defines it. - Run the code with each failing input from step 2. Confirm that each one returns an
Errorthat names its cause, and that valid input gives the same result as before.
Verify
Run the proof script from the skill root:
pwsh ./scripts/run.ps1The script shows each unsafe form failing and each safe form reporting the failure. It fails when an expected result does not occur.
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.

