Skip to content

any chance of having something like #[serde(crate = "...")] for thiserror? #386

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

Closed
hmacias-avaya opened this issue Nov 11, 2024 · 5 comments

Comments

@hmacias-avaya
Copy link

I'm trying to use the latest thiserror 2 and until now I was reexporting thiserror from a common dependency so my "end project" was not depending on thiserror directly.
Now this is no longer possible and is mentioned on the breaking changes section:

Code containing invocations of thiserror's derive(Error) must now have a direct dependency on the thiserror crate regardless of the error data structure's contents

is there any chance of having something like serde's 'crate' annotation in order to be able to use thiserror derives without depending on thiserror directly?
https://serde.rs/container-attrs.html#crate

This seems to work nicely when using serde's derives; perhaps it could work here as well?

@dtolnay
Copy link
Owner

dtolnay commented Nov 11, 2024

I would prefer not to support this.

@dtolnay dtolnay closed this as completed Nov 11, 2024
@j-a-m-l
Copy link

j-a-m-l commented Dec 17, 2024

@hmacias-avaya as an alternative you could try something like this:

External lib common_lib:

pub use thiserror::*;

And then trick thiserror to use the common library:

extern crate common_lib as thiserror;

@hmacias-avaya
Copy link
Author

thanks, I'll give it a try.

@Kitt3120
Copy link

Kitt3120 commented Mar 4, 2025

@hmacias-avaya as an alternative you could try something like this:

External lib common_lib:

pub use thiserror::*;

And then trick thiserror to use the common library:

extern crate common_lib as thiserror;

At first I thought that it works, vs code does not show any errors using rust-analyzer. But when compiling, it fails:

use thiserror::Error;

#[derive(Debug, Error)]
pub enum TestError {
    #[error("Test {0}")]
    PleaseWork(String),
}
error: cannot find attribute `error` in this scope
   --> src/types.rs:124:7
    |
124 |     #[error("Test {0}")]
    |       ^^^^^

For more information about this error, try `rustc --explain E0432`.

So, I can just say that I'd also love to have this feature. I am unaware of how this affects the code exactly. If it makes things very complicated and way harder to maintain, it's not worth it, of course. But if that's not the case, I kindly ask for this feature again.

@dtolnay
Copy link
Owner

dtolnay commented Mar 5, 2025

If anyone would like to work on this, rust-lang/rust#54363 (comment) has a writeup of my preferred approach.

FirelightFlagboy added a commit to Scille/parsec-cloud that referenced this issue Mar 24, 2025
This require add `thiserror` as direct dependencies of crate that use.
Our previous way of providing `thiserror` from a utils crate no longer
work CF issue [dtolnay/thiserror#386](dtolnay/thiserror#386).

This could be fixed by
[rust-lang/rust#54363](rust-lang/rust#54363).
FirelightFlagboy added a commit to Scille/parsec-cloud that referenced this issue Mar 24, 2025
This require add `thiserror` as direct dependencies of crate that use.
Our previous way of providing `thiserror` from a utils crate no longer
work CF issue [dtolnay/thiserror#386](dtolnay/thiserror#386).

This could be fixed by
[rust-lang/rust#54363](rust-lang/rust#54363).

To limit further error, `thiserror` is not longer re-exported by
`libparsec_types`.
FirelightFlagboy added a commit to Scille/parsec-cloud that referenced this issue Mar 24, 2025
This require add `thiserror` as direct dependencies of crate that use.
Our previous way of providing `thiserror` from a utils crate no longer
work CF issue [dtolnay/thiserror#386](dtolnay/thiserror#386).

This could be fixed by
[rust-lang/rust#54363](rust-lang/rust#54363).

To limit further error, `thiserror` is not longer re-exported by
`libparsec_types`.
github-merge-queue bot pushed a commit to Scille/parsec-cloud that referenced this issue Mar 24, 2025
This require add `thiserror` as direct dependencies of crate that use.
Our previous way of providing `thiserror` from a utils crate no longer
work CF issue [dtolnay/thiserror#386](dtolnay/thiserror#386).

This could be fixed by
[rust-lang/rust#54363](rust-lang/rust#54363).

To limit further error, `thiserror` is not longer re-exported by
`libparsec_types`.
Kitt3120 added a commit to lum-rs/lum_libs that referenced this issue May 18, 2025
Kitt3120 added a commit to lum-rs/lum_libs that referenced this issue May 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants