Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forward() attribute undocumented #320

Open
rydrman opened this issue Nov 12, 2023 · 1 comment
Open

forward() attribute undocumented #320

rydrman opened this issue Nov 12, 2023 · 1 comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed

Comments

@rydrman
Copy link

rydrman commented Nov 12, 2023

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
Copy link
Author

rydrman commented Nov 12, 2023

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;
}

@zkat zkat added documentation Improvements or additions to documentation help wanted Extra attention is needed labels Feb 4, 2024
@zkat zkat changed the title Cannot use transparent with global attributes forward() attribute undocumented Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants