Need help with FsToolkit.ErrorHandling?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

demystifyfp
259 Stars 39 Forks MIT License 377 Commits 9 Opened issues

Description

An opinionated F# Library for error handling

Services available

!
?

Need anything else?

Contributors list

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
,
Result
,
Async>
,
Async>
, and
Result
.

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.

Builds

GitHub Actions

GitHub Actions
Build History

NuGet

| Package name | Badge | | --- | --- | | FsToolkit.ErrorHandling | NuGet | FsToolkit.ErrorHandling.TaskResult | NuGet | FsToolkit.ErrorHandling.JobResult | NuGet

Developing locally

Requirements

  • .NET Core SDK
    • v3.1.200 or higher
    • Install from here.
  • Node
    • v10.15.0 or LTS
    • Not required but recommend that you use NVM to easily manage multiple versions of Node

Compiling

> build.cmd  // on windows
$ ./build.sh  // 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
//   isPwdValid: string -> User -> bool
//   authorize: User -> Async>
//   createAuthToken: User -> Result

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

let login (username: string) (password: string) : Async> = 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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.