README.md

# gleyre

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

Pronounced like the English word "glare", this `gleyre` is based on the
error-handling model from the Rust crate
[`eyre`](https://docs.rs/eyre/0.6.12/eyre/). (`eyre` is, itself, a fork of
`anyhow`.)


In your `gleam.toml`:

```toml
gleyre = { git = "https://codeberg.org/d2718/gleyre", ref = "main" }
```

In your application:

```gleam
import gleyre.{type Outcome}
import your_mod.{type Config, type Thing}

fn lowest_level(path: String) -> Outcome(Thing) {
  your_mod.load_thing(path) |> gleyre.from()
}

fn middle_level(cfg: Config) -> Outcome(Thing) {
  let path = your_mod.get_path(cfg)
  lowest_level(path)
  |> gleyre.wrap(string.append("attempting to load Thing from ", path))
}

fn high_level(config_str: String) -> Outcome(Thing) {
  use cfg <- gleyre.try_or_wrap(
    your_mod.parse_config(config_str),
    string.append("parsing config string: ", config_str)
  )

  middle_level(cfg)
  |> gleyre.wrap("middle_level operation failed")
}

pub fn highest_level() {
  case high_level(config_str) {
    Okay(thing) -> {
      do_thing(thing)
      io.println("Success! You did the thing.")
    Err(e) -> {
      gleyre.to_string(e)
      |> io.println_error()
    }
  }
}
```