zkat / miette

Fancy extension for std::error::Error with pretty, detailed diagnostic printing.
https://docs.rs/miette
Apache License 2.0
2.01k stars 114 forks source link

forward() attribute undocumented #320

Open rydrman opened 11 months ago

rydrman commented 11 months ago

It seems like you cannot mix transparent with any enum-level attributes, eg:

#[derive(miette::Diagnostic, thiserror::Error, Debug)]
#[diagnostic(url("http://mylib.example"))]
enum Error {
    #[error(transparent)]
    #[diagnostic(transparent)]
    External(#[from] external::Error),
}

mod external {
    #[derive(miette::Diagnostic, thiserror::Error, Debug)]
    #[error("external error")]
    pub struct Error;
}

results in error: diagnostic(transparent) not allowed in combination with other args

I believe that I understand how this error is coming to pass, but in my case of having my library split among multiple crates, and my error enums being quite long it seems like too much to replicate the enum-level attributes for all other variants.

In this case, I think it would be reasonable to ignore the enum-level attributes for any variant that uses transparent, or maybe there's some alternate syntax or feature that I am missing for this case?

rydrman commented 11 months ago

After some digging in the codebase, it seems like forward(0) already exists to handle this case, perhaps this can be added to the documentation?

#[derive(miette::Diagnostic, thiserror::Error, Debug)]
#[diagnostic(url("http://mylib.example"))]
enum Error {
    #[error(transparent)]
    #[diagnostic(forward(0)]
    External(#[from] external::Error),
}

mod external {
    #[derive(miette::Diagnostic, thiserror::Error, Debug)]
    #[error("external error")]
    pub struct Error;
}