Feather.ErrorHandling
2.1.0
dotnet add package Feather.ErrorHandling --version 2.1.0
NuGet\Install-Package Feather.ErrorHandling -Version 2.1.0
<PackageReference Include="Feather.ErrorHandling" Version="2.1.0" />
<PackageVersion Include="Feather.ErrorHandling" Version="2.1.0" />
<PackageReference Include="Feather.ErrorHandling" />
paket add Feather.ErrorHandling --version 2.1.0
#r "nuget: Feather.ErrorHandling, 2.1.0"
#:package Feather.ErrorHandling@2.1.0
#addin nuget:?package=Feather.ErrorHandling&version=2.1.0
#tool nuget:?package=Feather.ErrorHandling&version=2.1.0
<img src="https://github.com/FeatherTools/.github/blob/main/profile/feather-logo-200.png" alt="FeatherTools Logo" width="100" height="100"> Error-Handling
Library for proper error handling with Option, Result, AsyncResult and their computation expressions.
Inspiration
- Started as a copy of https://github.com/swlaschin/DomainModelingMadeFunctional/blob/master/src/OrderTaking/Result.fs
- Similar project is https://github.com/fsprojects/Chessie
- Also Inspired by Suave/YoLo
Install
paket add Feather.ErrorHandling
Note: You can also use this library in a Fable project.
Validation
validation {} is applicative. It evaluates every binding joined with and! and collects all of their failures.
You can bind a Result<'T, 'Failure> or a Validation<'T, 'Failure> directly.
open Feather.ErrorHandling
type Person = { Name: string; Age: int }
type PersonError =
| NameEmpty
| InvalidAge
| AgeNegative
| Underage
module Int32 =
let tryParse (s: string) =
match System.Int32.TryParse(s) with
| true, value -> Some value
| false, _ -> None
let validateName name = if name = "" then Error NameEmpty else Ok name
let createPerson name age: Validation<Person, PersonError> = validation {
let! name = validateName name
and! age = result { // only one specific error may come from the result
let! age = age |> Int32.tryParse |> Result.ofOption InvalidAge
if age < 0 then return! Error AgeNegative
if age < 18 then return! Error Underage
return age
}
return { Name = name; Age = age }
}
createPerson "Alice" "30" // Ok { Name = "Alice"; Age = 30 }
createPerson "Alice" "thirty" // Error [ InvalidAge ]
createPerson "" "-1" // Error [ NameEmpty; AgeNegative ]
createPerson "Alice" "16" // Error [ Underage ]
A Validation<'T, 'Failure> is a Result<'T, 'Failure list>, so when a stage should run only if the previous one
succeeded, bind the stages in an outer result {}.
Release
- Increment version in
ErrorHandling.fsproj - Update
CHANGELOG.md - Commit new version and tag it
Development
Requirements
Build
./build.sh build
Tests
./build.sh -t tests
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- FSharp.Core (>= 10.0.100 && < 11.0.0)
NuGet packages (23)
Showing the top 5 NuGet packages that depend on Feather.ErrorHandling:
| Package | Downloads |
|---|---|
|
Alma.Logging
Library for Logging to the terminal. |
|
|
Alma.Kafka
Library for reading messages or producing messages to/from stream. |
|
|
Alma.State
Library for handling internal memory state (_concurrently, etc._). |
|
|
Alma.Tracing
A library to help with tracing. |
|
|
Alma.Metrics
Library for showing app metrics for prometheus. |
GitHub repositories
This package is not used by any popular GitHub repositories.