All Projects → demystifyfp → Fstoolkit.errorhandling

demystifyfp / Fstoolkit.errorhandling

Licence: mit
An opinionated F# Library for error handling

Programming Languages

fsharp
127 projects

Projects that are alternatives of or similar to Fstoolkit.errorhandling

Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (-32%)
Mutual labels:  error-handling
Bugsnag Cocoa
Bugsnag crash reporting for iOS, macOS and tvOS apps
Stars: ✭ 167 (-16.5%)
Mutual labels:  error-handling
Functional Examples
Examples with Functional JavaScript, following Professor Frisby's course
Stars: ✭ 179 (-10.5%)
Mutual labels:  category-theory
Raven Weapp
Sentry SDK for WeApp
Stars: ✭ 142 (-29%)
Mutual labels:  error-handling
Bugsnag Go
Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
Stars: ✭ 155 (-22.5%)
Mutual labels:  error-handling
Graphql Errors
Simple error handler for GraphQL Ruby ❗️
Stars: ✭ 170 (-15%)
Mutual labels:  error-handling
Naive functional programming
A naive approach to functional programming using TypeScript
Stars: ✭ 129 (-35.5%)
Mutual labels:  category-theory
Exceptions4c
🐑 An exception handling framework for C
Stars: ✭ 189 (-5.5%)
Mutual labels:  error-handling
Underlinetextfield
Simple UITextfield Subclass with state
Stars: ✭ 156 (-22%)
Mutual labels:  error-handling
Swift Error Handler
Error handling library for Swift
Stars: ✭ 172 (-14%)
Mutual labels:  error-handling
Lawvere
A categorical programming language with effects
Stars: ✭ 142 (-29%)
Mutual labels:  category-theory
Discopy
a toolbox for computing with monoidal categories
Stars: ✭ 148 (-26%)
Mutual labels:  category-theory
Exceptionless
Exceptionless server and jobs
Stars: ✭ 2,107 (+953.5%)
Mutual labels:  error-handling
Categories
Categories parametrized by morphism equality, in Agda
Stars: ✭ 141 (-29.5%)
Mutual labels:  category-theory
Slashtrace
Awesome error handler. Demo: https://slashtrace.com/demo.php
Stars: ✭ 182 (-9%)
Mutual labels:  error-handling
Cql
CQL: Categorical Query Language implementation in Haskell
Stars: ✭ 132 (-34%)
Mutual labels:  category-theory
Pyrollbar
Error tracking and logging from Python to Rollbar
Stars: ✭ 169 (-15.5%)
Mutual labels:  error-handling
Cql
Categorical Query Language IDE
Stars: ✭ 196 (-2%)
Mutual labels:  category-theory
Failure
failure is a utility package for handling application errors.
Stars: ✭ 187 (-6.5%)
Mutual labels:  error-handling
Whoops
PHP errors for cool kids
Stars: ✭ 12,646 (+6223%)
Mutual labels:  error-handling

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.

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 <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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].