facet-error

Crates.iofacet-error
lib.rsfacet-error
version0.43.2
created_at2025-12-28 12:29:03.921741+00
updated_at2026-01-23 18:04:20.584367+00
descriptionthiserror replacement powered by facet - derive Error trait from doc comments
homepage
repositoryhttps://github.com/facet-rs/facet
max_upload_size
id2008715
size25,740
Amos Wenger (fasterthanlime)

documentation

README

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:

GitHub Sponsors Patreon

...along with corporate sponsors:

AWS Zed Depot

...without whom this work could not exist.

Special thanks

The facet logo was drawn by Misiasart.

License

Licensed under either of:

at your option.

Commit count: 3380

cargo fmt