#error #error-message #derive-error #proc-macro #thiserror #docs #generate

error-doc

A simple proc macro to generate #[doc] comments from #[error] messages

2 unstable releases

0.2.0 Aug 21, 2024
0.1.0 Aug 17, 2024

#1820 in Rust patterns

Download history 22/week @ 2024-09-27 19/week @ 2024-10-04 8/week @ 2024-10-11 14/week @ 2024-10-18 22/week @ 2024-10-25 24/week @ 2024-11-01 20/week @ 2024-11-08 37/week @ 2024-11-15 35/week @ 2024-11-22 41/week @ 2024-11-29 52/week @ 2024-12-06 91/week @ 2024-12-13 7/week @ 2024-12-20 11/week @ 2024-12-27 13/week @ 2025-01-03 21/week @ 2025-01-10

54 downloads per month

MIT/Apache

5KB

error-doc

A simple proc macro to generate #[doc] comments from #[error] messages

Usage

The errors macro derives thiserror::Error and core::fmt::Debug traits, and automatically generates missing documents for error variants from error messages.

Using error_doc macro, you can also derive Error and Debug trait separately.

Example

#[error_doc::errors]
pub enum SomeError {
    #[error("failed to open config file")]
    OpenFile(#[from] std::io::Error),
    #[error(transparent)]
    #[doc = "Database error"]
    Database(#[from] sqlx::Error),
    #[error("unexpected value: `{0}`")]
    #[doc = "Unexpected value is provided"]
    UnexpectedValue(u16),
    #[error("some other error")]
    Other,
}

and

#[error_doc::error_doc]
#[derive(thiserror::Error, Debug)]
pub enum SomeError {
    #[error("failed to open config file")]
    OpenFile(#[from] std::io::Error),
    #[error(transparent)]
    #[doc = "Database error"]
    Database(#[from] sqlx::Error),
    #[error("unexpected value: `{0}`")]
    #[doc = "Unexpected value is provided"]
    UnexpectedValue(u16),
    #[error("some other error")]
    Other,
}

generates

#[derive(thiserror::Error, Debug)]
pub enum SomeError {
    #[error("failed to open config file")]
    #[doc = "Failed to open config file"]
    OpenFile(#[from] std::io::Error),
    #[error(transparent)]
    #[doc = "Database error"]
    Database(#[from] sqlx::Error),
    #[error("unexpected value: `{0}`")]
    #[doc = "Unexpected value is provided"]
    UnexpectedValue(u16),
    #[error("some other error")]
    #[doc = "Some other error"]
    Other,
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~245–710KB
~17K SLoC