{"id":13681475,"url":"https://github.com/demystifyfp/FsToolkit.ErrorHandling","last_synced_at":"2025-04-30T03:31:36.684Z","repository":{"id":33915117,"uuid":"141843316","full_name":"demystifyfp/FsToolkit.ErrorHandling","owner":"demystifyfp","description":"An opinionated F# Library for error handling","archived":false,"fork":false,"pushed_at":"2025-03-30T19:20:28.000Z","size":4236,"stargazers_count":497,"open_issues_count":15,"forks_count":64,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-14T22:18:29.459Z","etag":null,"topics":["category-theory","error-handling","fsharp","railway-oriented-programming"],"latest_commit_sha":null,"homepage":"https://demystifyfp.gitbook.io/fstoolkit-errorhandling","language":"F#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/demystifyfp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-07-21T20:18:19.000Z","updated_at":"2025-04-09T15:30:59.000Z","dependencies_parsed_at":"2023-10-16T23:58:18.976Z","dependency_job_id":"ab45ef50-c036-4a1b-be1a-6ac094486439","html_url":"https://github.com/demystifyfp/FsToolkit.ErrorHandling","commit_stats":{"total_commits":653,"total_committers":41,"mean_commits":"15.926829268292684","dds":0.6125574272588055,"last_synced_commit":"d01168389716a1f4071a337be41c1cb698c14def"},"previous_names":[],"tags_count":135,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demystifyfp%2FFsToolkit.ErrorHandling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demystifyfp%2FFsToolkit.ErrorHandling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demystifyfp%2FFsToolkit.ErrorHandling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demystifyfp%2FFsToolkit.ErrorHandling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/demystifyfp","download_url":"https://codeload.github.com/demystifyfp/FsToolkit.ErrorHandling/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251635307,"owners_count":21619204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["category-theory","error-handling","fsharp","railway-oriented-programming"],"created_at":"2024-08-02T13:01:31.228Z","updated_at":"2025-04-30T03:31:36.664Z","avatar_url":"https://github.com/demystifyfp.png","language":"F#","funding_links":[],"categories":["F#","General Purpose Libraries"],"sub_categories":["Performance Analysis"],"readme":"# FsToolkit.ErrorHandling\n\n**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.\n\nThe library provides utility functions like `map`, `bind`, `apply`, `traverse`, `sequence` as well as computation expressions and infix operators to work with `Result\u003c'a, 'b\u003e`, `Result\u003c'a option, 'b\u003e`, `Async\u003cResult\u003c'a, 'b\u003e\u003e`, `Async\u003cResult\u003c'a option, 'b\u003e\u003e`, and `Result\u003c'a, 'b list\u003e`.\n\nIt was inspired by [Chessie](https://github.com/fsprojects/Chessie) and Cvdm.ErrorHandling (the latter has now been merged into FsToolkit.ErrorHandling).\n\nFsToolkit.ErrorHandling targets .NET Standard 2.0, .NET Standard2.1 and supports Fable.\n\n## Documentation\n\nThe documentation is [available here](https://demystifyfp.gitbook.io/fstoolkit-errorhandling).\n\n## Further material\n\n* The main resource as to learning this style of programming [Railway Oriented Programming](https://fsharpforfunandprofit.com/rop/)\n* However Result isn't a panacea, see what pitfalls and where you shouldn't use `Result`. [In defense of Exceptions: Throw (away) your Result](https://www.youtube.com/watch?v=E4dI-zd4Cag)\n\n## Builds\n\nGitHub Actions |\n:---: |\n[![GitHub Actions](https://github.com/demystifyfp/FsToolkit.ErrorHandling/workflows/Build%20master/badge.svg)](https://github.com/demystifyfp/FsToolkit.ErrorHandling/actions?query=branch%3Amaster) |\n[![Build History](https://buildstats.info/github/chart/demystifyfp/FsToolkit.ErrorHandling?branch=master)](https://github.com/demystifyfp/FsToolkit.ErrorHandling/actions?query=branch%3Amaster) |\n\n### NuGet\n\n| Package name | Release | Prelease\n| --- | --- | --- |\n| FsToolkit.ErrorHandling | [![NuGet](https://buildstats.info/nuget/FsToolkit.ErrorHandling)](https://www.nuget.org/packages/FsToolkit.ErrorHandling) | [![NuGet](https://buildstats.info/nuget/FsToolkit.ErrorHandling?includePreReleases=true)](https://www.nuget.org/packages/FsToolkit.ErrorHandling/absoluteLatest)\n| FsToolkit.ErrorHandling.TaskResult | [![NuGet](https://buildstats.info/nuget/FsToolkit.ErrorHandling.TaskResult)](https://www.nuget.org/packages/FsToolkit.ErrorHandling.TaskResult) | [![NuGet](https://buildstats.info/nuget/FsToolkit.ErrorHandling.TaskResult?includePreReleases=true)](https://www.nuget.org/packages/FsToolkit.ErrorHandling.TaskResult/absoluteLatest)\n| FsToolkit.ErrorHandling.JobResult | [![NuGet](https://buildstats.info/nuget/FsToolkit.ErrorHandling.JobResult)](https://www.nuget.org/packages/FsToolkit.ErrorHandling.JobResult) | [![NuGet](https://buildstats.info/nuget/FsToolkit.ErrorHandling.JobResult?includePreReleases=true)](https://www.nuget.org/packages/FsToolkit.ErrorHandling.JobResult/absoluteLatest)\n| FsToolkit.ErrorHandling.AsyncSeq | [![NuGet](https://buildstats.info/nuget/FsToolkit.ErrorHandling.AsyncSeq)](https://www.nuget.org/packages/FsToolkit.ErrorHandling.AsyncSeq) | [![NuGet](https://buildstats.info/nuget/FsToolkit.ErrorHandling.AsyncSeq?includePreReleases=true)](https://www.nuget.org/packages/FsToolkit.ErrorHandling.AsyncSeq/absoluteLatest)\n| FsToolkit.ErrorHandling.IcedTasks | [![NuGet](https://buildstats.info/nuget/FsToolkit.ErrorHandling.IcedTasks)](https://www.nuget.org/packages/FsToolkit.ErrorHandling.IcedTasks) | [![NuGet](https://buildstats.info/nuget/FsToolkit.ErrorHandling.IcedTasks?includePreReleases=true)](https://www.nuget.org/packages/FsToolkit.ErrorHandling.IcedTasks/absoluteLatest)\n\n## Developing locally\n\n### Devcontainer \nThis repository has a devcontainer setup for VSCode. For more information see:\n- [VSCode](https://code.visualstudio.com/docs/devcontainers/containers)\n\n### Local Setup\n\n* [.NET Core SDK](https://www.microsoft.com/net/download/)\n  * [v6.x](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)\n  * [v7.x](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)\n  * [v8.x](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)\n\n#### Optional \n\nTo test fable builds locally you will need:\n\n* [Node](https://nodejs.org/en/)\n  * v18.0.0 or Higher\n  * Not required but recommend that you use [NVM](https://github.com/nvm-sh/nvm) to easily manage multiple versions of Node\n* [Python](https://www.python.org/downloads/)\n  * v3.10.0 or higher\n  * Required for Fable-Python\n\n\n#### Compiling\n\n```bash\n\u003e build.cmd \u003coptional buildtarget\u003e // on windows\n$ ./build.sh  \u003coptional buildtarget\u003e// on unix\n```\n\nWithout specifying a build target, the default target is `DotnetPack`, which will run tests for all projects on dotnet and then pack the projects into nuget packages. For additional notable targets see below.\n\n##### Build Targets\n\n- `Clean` - Will clean all projects `bin` and `obj` folders\n- `DotnetTest` - Will run tests for `dotnet` projects\n- `NpmTest` - Will run tests for `fable-javascript` projects\n- `PythonTest` - Will run tests for `fable-python` projects\n- `RunTests` - Will run tests for `dotnet`, `fable-javascript` and `fable-python` projects\n- `FormatCode` - Will run `fantomas` to format the codebase\n\nThis is not an exhaustive list. Additional targets can be found in the `./build/build.fs` file.\n\n\nA motivating example\n--------------------\n\nThis 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](https://demystifyfp.gitbook.io/fstoolkit-errorhandling) for details.)\n\n```f#\n// Given the following functions:\n//   tryGetUser: string -\u003e Async\u003cUser option\u003e\n//   isPwdValid: string -\u003e User -\u003e bool\n//   authorize: User -\u003e Async\u003cResult\u003cunit, AuthError\u003e\u003e\n//   createAuthToken: User -\u003e Result\u003cAuthToken, TokenError\u003e\n\ntype LoginError = InvalidUser | InvalidPwd | Unauthorized of AuthError | TokenErr of TokenError\n\nlet login (username: string) (password: string) : Async\u003cResult\u003cAuthToken, LoginError\u003e\u003e =\n  asyncResult {\n    // requireSome unwraps a Some value or gives the specified error if None\n    let! user = username |\u003e tryGetUser |\u003e AsyncResult.requireSome InvalidUser\n\n    // requireTrue gives the specified error if false\n    do! user |\u003e isPwdValid password |\u003e Result.requireTrue InvalidPwd\n\n    // Error value is wrapped/transformed (Unauthorized has signature AuthError -\u003e LoginError)\n    do! user |\u003e authorize |\u003e AsyncResult.mapError Unauthorized\n\n    // Same as above, but synchronous, so we use the built-in mapError\n    return! user |\u003e createAuthToken |\u003e Result.mapError TokenErr\n  }\n```\n\n## Sponsor(s)\n\n\u003ca href=\"https://www.ajira.tech\"\u003e\u003cimg src=\"./Ajira-logo.png\" alt=\"Ajira Technologies, India\" width=\"200\" /\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemystifyfp%2FFsToolkit.ErrorHandling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdemystifyfp%2FFsToolkit.ErrorHandling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemystifyfp%2FFsToolkit.ErrorHandling/lists"}