A (mostly) drop-in replacement for Rust's Result that provides backtrace support

Related tags

Miscellaneous errant
Overview

Errant

A (mostly) drop-in replacement for Rust's Result that provides backtrace support.

Please note that Errant is still very early in development and is not yet ready for general use.

Example

Here's an example of errant being used to trace a runtime error.

Result { Ok(baz(x)? + y) } fn foo(x: i32) -> Result { Ok(bar(x, 3)? * 2) } fn main() -> Result<(), &'static str> { foo(3)?; Ok(()) }">
use errant::prelude::*;

fn baz(_: i32) -> Result<i32, &'static str> {
    Err("Uh oh!")
}

fn bar(x: i32, y: i32) -> Result<i32, &'static str> {
    Ok(baz(x)? + y)
}

fn foo(x: i32) -> Result<i32, &'static str> {
    Ok(bar(x, 3)? * 2)
}

fn main() -> Result<(), &'static str> {
    foo(3)?;
    Ok(())
}

The result of this program is as follows (color omitted).

Error: "Uh oh!"
    ╭─[examples/hello.rs:1:1]
    │
  4 │     Err("Uh oh!")
    ·     ┬
    ·     ╰── Error encountered here
  8 │     Ok(baz(x)? + y)
    ·        ┬
    ·        ╰── (1) Then propagated here
 12 │     Ok(bar(x, 3)? * 2)
    ·        ┬
    ·        ╰── (2) Then propagated here
 16 │     foo(3)?;
    ·     ┬
    ·     ╰── (3) Then propagated here
────╯

Give it a go with the following command.

cargo run --example hello

Design

Errant provides a replacement for std's Result type that automatically tracks error propagation through a program, generating a backtrace. In addition, it also provides a variety of error wrapper types that can be used to embellish errors with extra context when desired, such as the Backtrace error. When a panic occurs, Errant will display a backtrace of the error that includes useful information like propagation locations, context provided along the way, and more.

Philosophy

  • Errors should be types, not trait objects
  • Errors should point to their source and show their path through the program
  • Errors should be zero-cost, requiring no (or very little) overhead in release mode

License

errant is distributed under either of:

at the disgression of the user.

You might also like...
Provides two APIs for easily cancelling futures, with the option to fallback to a timeout cancellation

tokio-context Provides two different methods for cancelling futures with a provided handle for cancelling all related futures, with a fallback timeout

global allocator that provides hooks for tracking allocation events

tracking-allocator A GlobalAlloc-compatible allocator implementation that provides the ability to track allocation events. examples As allocators are

`fugit` provides a comprehensive library of `Duration` and `Instant` for the handling of time in embedded systems, doing all it can at compile time.

fugit fugit provides a comprehensive library of Duration and Instant for the handling of time in embedded systems, doing all it can at compile time. T

cooptex provides deadlock-free Mutexes.

cooptex provides deadlock-free Mutexes. The [CoopMutex::lock] method wraps the [std::sync::Mutex] return value with a Result that will request

Provides a Suricata Eve output for Kafka with Suricate Eve plugin

Suricata Eve Kafka Output Plugin for Suricata 6.0.x This plugin provides a Suricata Eve output for Kafka. Base on suricata-redis-output: https://githu

Provides a wrapper to deserialize clap app using serde.

clap-serde Provides a wrapper to deserialize clap app using serde. API Reference toml const CLAP_TOML: &'static str = r#" name = "app_clap_serde" vers

This repository provides an emulator for iterated prisoner's dilemma.

Iterated Prisoner's Dilemma Emulator Name This repository provides an emulator for iterated prisoner's dilemma. Description You can run the program by

Memory.lol - a tiny web service that provides historical information about social media accounts

memory.lol Overview This project is a tiny web service that provides historical information about social media accounts. It can currently be used to l

Simple library to host lv2 plugins. Is not meant to support any kind of GUI.

lv2-host-minimal Simple library to host lv2 plugins. Is not meant to support any kind of GUI. Host fx plugins (audio in, audio out) Set parameters Hos

Owner
Joshua Barretto
Interested in things. He/him.
Joshua Barretto
Rustyread is a drop in replacement of badread simulate.

Rustyread is a drop in replacement of badread simulate. Rustyread is very heavily inspired by badread, it reuses the same error and quality model file. But Rustyreads is multi-threaded and benefits from other optimizations.

Pierre Marijon 20 Oct 1, 2022
Modern Drop-in Replacement for Nginx AutoIndex / FancyIndex!

MeowIndex A cute, feature-rich file listing module to replace nginx's autoindex / fancyindex. Features List files Show file icons Clickable, length-sa

Hykilpikonna 4 Feb 25, 2023
Backtrace for ESP32 bare-metal

esp-backtrace - backtrace for ESP32 bare-metal supports ESP32, ESP32C3, ESP32S2, ESP32S3 optional features: panic-handler, exception-handler (will ena

esp-rs 10 Dec 14, 2022
Fast, concurrent, arena-based allocator with drop support

blink-alloc Blink-alloc is extremely fast allocator based on the common idea of allocating linearly zipping a cursor through memory chunk and reset ev

Zakarum 55 Mar 5, 2023
The cumulative sibling of `Result` and `Either`.

validated The cumulative sibling of Result and Either. The Validated type has special FromIterator instances that enable all errors in a sequence to b

Colin Woodbury 17 Nov 13, 2022
CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" format.

Lighthouse Groupie CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" form

Polestar 1 Jan 12, 2022
A flexible, simple to use, immutable, clone-efficient String replacement for Rust

flexstr A flexible, simple to use, immutable, clone-efficient String replacement for Rust Overview Rust is great, but it's String type is optimized as

Scott Meeuwsen 119 Dec 12, 2022
A direct replacement for `assert_eq` for unordered collections

assert_unordered A direct replacement for assert_eq for unordered collections This macro is useful for any situation where the ordering of the collect

Scott Meeuwsen 10 Nov 29, 2022
This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you specified.

prae This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you spec

null 96 Dec 4, 2022
todo-or-die provides procedural macros that act as checked reminders.

todo-or-die provides procedural macros that act as checked reminders.

David Pedersen 552 Dec 24, 2022