FsToolkit.ErrorHandling 3.0.0-beta005

FsToolkit.ErrorHandling

FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling.

The library provides utility functions like map, bind, apply, traverse, sequence as well as computation expressions and infix operators to work with Result<'a, 'b>, Result<'a option, 'b>, Async<Result<'a, 'b>>, Async<Result<'a option, 'b>>, and Result<'a, 'b list>.

It was inspired by Chessie and Cvdm.ErrorHandling (the latter has now been merged into FsToolkit.ErrorHandling).

FsToolkit.ErrorHandling targets .NET Standard 2.0 and .NET Framework 4.6.1 and supports Fable.

Documentation

The documentation is available here.

Further material

Builds

GitHub Actions
GitHub Actions
Build History

NuGet

Package name Release Prelease
FsToolkit.ErrorHandling NuGet NuGet
FsToolkit.ErrorHandling.TaskResult NuGet NuGet
FsToolkit.ErrorHandling.JobResult NuGet NuGet
FsToolkit.ErrorHandling.AsyncSeq NuGet NuGet
FsToolkit.ErrorHandling.IcedTasks NuGet NuGet

Developing locally

Requirements

Compiling

> build.cmd <optional buildtarget> // on windows
$ ./build.sh  <optional buildtarget>// on unix

A motivating example

This example of composing a login flow shows one example of how this library can aid in clear, simple, and powerful error handling, using just a computation expression and a few helper functions. (The library has many more helper functions and computation expressions as well as infix operators; see the documentation for details.)

// Given the following functions:
//   tryGetUser: string -> Async<User option>
//   isPwdValid: string -> User -> bool
//   authorize: User -> Async<Result<unit, AuthError>>
//   createAuthToken: User -> Result<AuthToken, TokenError>

type LoginError = InvalidUser | InvalidPwd | Unauthorized of AuthError | TokenErr of TokenError

let login (username: string) (password: string) : Async<Result<AuthToken, LoginError>> =
  asyncResult {
    // requireSome unwraps a Some value or gives the specified error if None
    let! user = username |> tryGetUser |> AsyncResult.requireSome InvalidUser

    // requireTrue gives the specified error if false
    do! user |> isPwdValid password |> Result.requireTrue InvalidPwd

    // Error value is wrapped/transformed (Unauthorized has signature AuthError -> LoginError)
    do! user |> authorize |> AsyncResult.mapError Unauthorized

    // Same as above, but synchronous, so we use the built-in mapError
    return! user |> createAuthToken |> Result.mapError TokenErr
  }

Sponsor(s)

Ajira Technologies, India

Showing the top 20 packages that depend on FsToolkit.ErrorHandling.

Packages Downloads
FsToolkit.ErrorHandling.TaskResult
FsToolkit.ErrorHandling is an extensive utility library based around the F# Result type, enabling consistent and powerful error handling.
23
NBomber
Very simple load testing framework for Pull and Push scenarios.
20
FsToolkit.ErrorHandling.TaskResult
FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling.
20
FsToolkit.ErrorHandling.TaskResult
Package Description
20
NBomber
Very simple load testing framework for Pull and Push scenarios.
19
FsToolkit.ErrorHandling.TaskResult
FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling.
19
FsToolkit.ErrorHandling.TaskResult
FsToolkit.ErrorHandling is an extensive utility library based around the F# Result type, enabling consistent and powerful error handling.
19

- [Moves many functions to inline with InlineIfLambda for performance](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/166) Credits [@TheAngryByrd](https://github.com/TheAngryByrd) - [Native Tasks for TaskResult, TaskOption, and TaskResultOption](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/169) Credits [@TheAngryByrd](https://github.com/TheAngryByrd) - [Add explicit type parameters to ignore functions](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/174) Credits [@cmeeren](https://github.com/cmeeren) - [Adds CancellableTaskResult](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/172) Credits [@TheAngryByrd](https://github.com/TheAngryByrd)

.NET Standard 2.0

.NET Standard 2.1

Version Downloads Last updated
5.1.0 5 10/01/2025
5.1.0-beta001 4 10/01/2025
5.0.1 6 07/19/2025
5.0.0 9 06/06/2025
5.0.0-beta014 10 06/06/2025
5.0.0-beta013 10 06/06/2025
5.0.0-beta012 14 05/04/2025
5.0.0-beta011 12 04/01/2025
5.0.0-beta010 14 03/29/2025
5.0.0-beta009 17 03/05/2025
5.0.0-beta008 12 03/03/2025
5.0.0-beta007 15 02/27/2025
5.0.0-beta006 12 02/27/2025
5.0.0-beta005 16 02/19/2025
5.0.0-beta004 15 02/14/2025
5.0.0-beta003 17 01/12/2025
5.0.0-beta002 16 01/01/2025
5.0.0-beta001 14 12/11/2024
4.18.0 17 11/28/2024
4.18.0-beta001 18 11/28/2024
4.17.0 14 10/06/2024
4.17.0-beta002 14 11/28/2024
4.17.0-beta001 17 10/06/2024
4.16.0 13 11/28/2024
4.15.3 17 10/06/2024
4.15.3-beta001 13 10/06/2024
4.15.2 17 10/06/2024
4.15.2-beta001 12 10/06/2024
4.15.1 16 11/28/2024
4.15.0 16 11/28/2024
4.14.0 18 10/06/2024
4.13.0 14 10/06/2024
4.13.0-beta002 15 10/22/2024
4.13.0-beta001 14 10/23/2024
4.12.0 18 10/06/2024
4.11.1 17 10/06/2024
4.11.0 17 10/06/2024
4.10.0 14 10/06/2024
4.9.0 12 11/28/2024
4.8.0 16 11/06/2024
4.7.0 12 11/28/2024
4.7.0-beta001 16 10/06/2024
4.6.0 17 10/06/2024
4.6.0-beta001 17 11/08/2024
4.5.0 13 11/14/2024
4.5.0-beta002 18 11/09/2024
4.5.0-beta001 17 10/06/2024
4.4.0 16 11/11/2024
4.3.0 17 10/06/2024
4.2.1 15 10/22/2024
4.2.0 13 10/20/2024
4.1.0 17 10/06/2024
4.1.0-beta001 17 10/23/2024
4.0.0 16 11/28/2024
4.0.0-beta001 17 10/22/2024
3.3.1 16 10/22/2024
3.3.1-beta004 14 10/06/2024
3.3.1-beta003 17 10/26/2024
3.3.1-beta002 14 11/21/2024
3.3.1-beta001 14 11/28/2024
3.3.0-beta001 14 11/28/2024
3.2.0 16 11/28/2024
3.2.0-beta001 18 11/06/2024
3.1.0 16 11/12/2024
3.0.1 16 10/06/2024
3.0.0 13 11/28/2024
3.0.0-beta008 17 10/20/2024
3.0.0-beta007 17 10/06/2024
3.0.0-beta006 16 10/06/2024
3.0.0-beta005 20 10/22/2024
3.0.0-beta004 17 10/06/2024
3.0.0-beta003 16 10/22/2024
3.0.0-beta002 13 11/28/2024
3.0.0-beta001 17 11/28/2024
2.13.0 12 11/28/2024
2.13.0-beta001 14 10/06/2024
2.12.0 16 11/28/2024
2.12.0-beta001 14 10/23/2024
2.11.1 16 10/06/2024
2.11.1-beta001 17 10/06/2024
2.11.0 13 11/28/2024
2.11.0-beta004 17 10/23/2024
2.11.0-beta002 20 10/06/2024
2.11.0-beta001 17 11/28/2024
2.10.0 16 11/28/2024
2.9.0 17 10/06/2024
2.9.0-beta001 17 11/28/2024
2.8.1 17 10/06/2024
2.8.0 13 10/06/2024
2.8.0-beta001 17 11/28/2024
2.7.1 15 11/28/2024
2.7.1-beta001 14 11/28/2024
2.7.0 13 11/28/2024
2.7.0-beta001 17 11/28/2024
2.6.0 16 11/28/2024
2.6.0-beta001 16 11/05/2024
2.5.0 13 10/06/2024
2.5.0-beta001 17 10/06/2024
2.4.0 14 10/06/2024
2.4.0-beta001 19 10/20/2024
2.3.0 13 10/21/2024
2.3.0-beta002 20 10/06/2024
2.2.0 17 10/06/2024
2.1.2 14 10/06/2024
2.1.1 16 10/06/2024
2.1.1-beta001 17 10/06/2024
2.1.0 17 10/06/2024
2.1.0-beta003 18 11/28/2024
2.1.0-beta002 20 10/06/2024
2.1.0-beta001 17 10/06/2024
2.0.0 17 11/28/2024
2.0.0-beta002 13 10/23/2024
2.0.0-beta001 17 10/06/2024
1.4.3 16 10/22/2024
1.4.0 14 10/06/2024
1.3.2 16 10/24/2024
1.3.1 16 10/06/2024
1.3.1-beta001 14 11/28/2024
1.3.0 17 10/06/2024
1.3.0-beta006 16 10/22/2024
1.3.0-beta005 17 10/26/2024
1.3.0-beta004 16 11/28/2024
1.2.6 15 11/28/2024
1.2.5 17 10/06/2024
1.2.4 16 11/28/2024
1.2.3 13 11/28/2024
1.2.2 16 11/28/2024
1.2.1 18 10/06/2024
1.1.1 15 10/22/2024
1.1.0 14 10/27/2024
1.0.0 17 10/06/2024
0.0.14 13 11/28/2024
0.0.13 17 11/28/2024
0.0.12 13 10/26/2024
0.0.11 16 11/28/2024
0.0.10 13 11/28/2024
0.0.9 13 11/28/2024
0.0.8 16 11/28/2024
0.0.7 13 10/22/2024
0.0.6 15 11/28/2024
0.0.5 14 10/27/2024
0.0.4 17 10/06/2024
0.0.3 16 10/23/2024
0.0.2 14 10/06/2024
0.0.1 15 11/28/2024