facet-error 0.36.0

thiserror replacement powered by facet - derive Error trait from doc comments
Documentation

facet-error

Coverage Status crates.io documentation MIT/Apache-2.0 licensed Discord

facet-error

A thiserror replacement powered by facet reflection. This crate is a plugin for #[derive(Facet)] that generates Display and Error trait implementations from doc comments.

Usage

use facet::Facet;

#[derive(Facet, Debug)]
#[facet(derive(Error))]
#[repr(u8)]
pub enum MyError {
    /// something went wrong
    Unknown,

    /// invalid value: {0}
    InvalidValue(String),

    /// invalid header (expected {expected}, found {found})
    InvalidHeader { expected: String, found: String },
}

This generates:

  • impl Display for MyError using doc comments as format strings
  • impl Error for MyError with proper source() implementation
  • Field interpolation works automatically for struct variants (e.g., {expected}, {found})
  • Tuple variants support positional interpolation (e.g., {0})

Features

  • Doc-driven Display: Doc comments become your error messages
  • Field interpolation: Reference struct fields by name in messages
  • Zero boilerplate: No manual Display or Error implementations
  • Integration with facet: Works seamlessly with the facet reflection system

Future Work

  • #[facet(error::source)] - mark fields as error sources
  • #[facet(error::from)] - generate From implementations
  • Support for error wrapping and transparent delegation

Sponsors

Thanks to all individual sponsors:

...along with corporate sponsors:

...without whom this work could not exist.

Special thanks

The facet logo was drawn by Misiasart.

License

Licensed under either of:

at your option.