# problem

[![Package Version](https://img.shields.io/hexpm/v/problem)](https://hex.pm/packages/problem)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/problem/)

An Error Handling library for Gleam. Inspired by
<https://github.com/lpil/snag> but with your own error type.

Problem gives you:

- An error stack that makes it easier to track the path of an error.
- Use your error type (instead of `String`).

```sh
gleam add problem
```

With this library you can add a stack to an error like:
```gleam
    let result = Error("Invalid email")
    |> problem.wrap
    |> problem.context("when validating email")
    |> problem.context("in signup")
```

Then you can print the stack:

```gleam
case result {
  Error(problem) -> {
    problem
    |> problem.pretty_print(function.identity)
    |> echo
  }
  _ -> {
    todo
  }
}
```

```text
Invalid email

stack:
  when validating email
  in signup
```
