agentleFS
TheAngryByrdTheAngryByrd/fsharp-skills/skills/fsharp-failure-paths/SKILL.md

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.

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
  1. Very specific:

    Do not call a partial function on a value that the type lets be empty or absent.

    line 18
  2. Very specific:

    Use the safe form and handle each case: List.tryHead, Seq.tryFind, Map.tryFind, Option pattern match.

    line 19
  3. Very specific:

    Use failwith and invalidArg only for a broken invariant that the caller cannot cause or recover from.

    line 21
  4. Very specific:

    When input, configuration, or a dependency can cause the failure, return Error.

    line 22
  5. Very specific:

    Use defaultArg and Option.defaultValue only when the contract defines the default.

    line 23
  6. Distinctive:

    When the value is required, report the absence.

    line 24
  7. Very specific:

    Do not catch every exception and return empty data.

    line 25
  8. Very specific:

    When several checks validate independent inputs, return every error.

    line 27
  9. Very specific:

    Use validation from FsToolkit.ErrorHandling, or collect the Error cases into a list.

    line 28
  10. Distinctive:

    Check each guard helper with a true and a false condition.

    line 29
  11. Distinctive:

    Read references/PATTERNS.md for each pattern with its unsafe form and its safe form.

    line 31
  12. Very specific:

    Run the code with each failing input from step 2.

    line 39
  13. Distinctive:

    Run the proof script from the skill root:

    line 43

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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, Option pattern match. A pattern match such as first :: _ is safe when the empty case also has a branch.
  • Use failwith and invalidArg only for a broken invariant that the caller cannot cause or recover from. When input, configuration, or a dependency can cause the failure, return Error.
  • Use defaultArg and Option.defaultValue only 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 errors and Result.bind chains stop at the first error. Use validation from FsToolkit.ErrorHandling, or collect the Error cases 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

  1. 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.
  2. For each item, name the input that makes it fail: empty collection, missing key, missing setting, failed dependency, or a second invalid value.
  3. Change each item that the input can reach to return Error with the cause. Keep each failwith only for a broken invariant, and keep each default only when the contract defines it.
  4. Run the code with each failing input from step 2. Confirm that each one returns an Error that 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.ps1

The script shows each unsafe form failing and each safe form reporting the failure. It fails when an expected result does not occur.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.