toobad 0.1.0

A simple, intuitive error handling library
Documentation
  • Coverage
  • 87.5%
    7 out of 8 items documented4 out of 4 items with examples
  • Size
  • Source code size: 26.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.52 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 40s Average build duration of successful builds.
  • all releases: 40s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • razkar-studio

toobad

Crates.io Version docs.rs License MIT License Apache-2.0 Crates.io Downloads Codeberg Stars Codeberg Issues Rust Edition Maintenance

Want better error handling? Well, toobad.

toobad is a simple, unbloated error handling library for Rust.

cargo add toobad
[dependencies]
toobad = "0.1"

The Basics

Any error type automatically converts into toobad::Error via ?:

use toobad::Result;

fn read_config() -> Result<String> {
    let content = std::fs::read_to_string("config.toml")?;
    Ok(content)
}

Adding Context

Wrap any Result or Option with a human-readable message:

use toobad::{Context, Result};

fn read_config() -> Result<String> {
    let content = std::fs::read_to_string("config.toml")
        .context("failed to read config file")?;
    Ok(content)
}

Prints as:

failed to read config file: No such file or directory (os error 2)

Works on Option too:

let value = some_map.get("key").context("key not found")?;

Creating Errors from Scratch

Use the toobad!() macro with full format!() support:

use toobad::toobad;

return Err(toobad!("expected {} items but got {}", expected, actual));

Or bail early with bail!():

use toobad::bail;

bail!("expected {} items but got {}", expected, actual);
// equivalent to: return Err(toobad!(...))

Or assert conditions with ensure!():

use toobad::ensure;

ensure!(x > 0, "x must be positive, got {}", x);
// equivalent to: if !condition { bail!(...) }

Downcasting

Recover the original error type when you need it:

if let Some(io_err) = error.downcast::<std::io::Error>() {
    match io_err.kind() {
        std::io::ErrorKind::NotFound => { /* handle missing file */ }
        _ => { /* handle other io errors */ }
    }
}

License

This project is licensed under either of MIT License or [Apache License, Version 2.0](LICENSE-APACHE at your option.

Cheers, RazkarStudio © 2026 RazkarStudio. All rights reserved