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

Error: use of unstable library feature 'error_generic_member_access #387

Closed
WhyNotHugo opened this issue Nov 12, 2024 · 13 comments
Closed

Comments

@WhyNotHugo
Copy link

The following fails to compile:

#[derive(Debug, thiserror::Error)]
pub struct Error {
    kind: ErrorKind,
    source: Option<Box<dyn std::error::Error + Send + Sync>>,
    backtrace: Backtrace,
}

Error output:

error[E0432]: unresolved import `thiserror`
   --> vstorage/src/lib.rs:159:17
    |
159 | #[derive(Debug, thiserror::Error)]
    |                 ^^^^^^^^^^^^^^^^ no `ThiserrorProvide` in `__private`
    |
note: found an item that was configured out
   --> /home/hugo/.local/state/cargo/registry/src/index.crates.io-6f17d22bba15001f/thiserror-1.0.47/src/lib.rs:257:29
    |
257 |     pub use crate::provide::ThiserrorProvide;
    |                             ^^^^^^^^^^^^^^^^
note: the item is gated here
   --> /home/hugo/.local/state/cargo/registry/src/index.crates.io-6f17d22bba15001f/thiserror-1.0.47/src/lib.rs:255:5
    |
255 |     #[cfg(error_generic_member_access)]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the derive macro `thiserror::Error` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: use of unstable library feature 'error_generic_member_access'
   --> vstorage/src/lib.rs:159:17
    |
159 | #[derive(Debug, thiserror::Error)]
    |                 ^^^^^^^^^^^^^^^^
    |
    = note: see issue #99301 <https://github.com/rust-lang/rust/issues/99301> for more information
    = note: this error originates in the derive macro `thiserror::Error` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `thiserror_provide` found for reference `&Box<dyn std::error::Error + Send + Sync>` in the current scope
   --> vstorage/src/lib.rs:162:5
    |
162 |     source: Option<Box<dyn std::error::Error + Send + Sync>>,
    |     ^^^^^^ method not found in `&Box<dyn Error + Send + Sync>`

#204 seems to be related. That was due to features not supported by Rust 1.65. I'm using 1.82.0.

It's not entirely clear to me what requires error_generic_member_access here. Using impl std::error::Error for Error {} instead of thiserror for the same type does work.

@dtolnay
Copy link
Owner

dtolnay commented Nov 12, 2024

Using Backtrace in errors requires a nightly compiler. This is mentioned in the readme.

@dtolnay dtolnay closed this as completed Nov 12, 2024
@WhyNotHugo
Copy link
Author

Using Backtrace in errors requires a nightly compiler. This is mentioned in the readme.

I can use Backtraces fine with the this stable compiler. Compilation works fine if I remove thiserror:

-#[derive(Debug, thiserror::Error)]
+#[derive(Debug)]
 pub struct Error {
     kind: ErrorKind,
     source: Option<Box<dyn std::error::Error + Send + Sync>>,
     backtrace: Backtrace,
 }

+impl std::error::Error for Error {}

Does thiserror have a different behaviour if my type has a backtrace: Backtrace? Can I disable this "different behaviour"?

@mhnap
Copy link

mhnap commented Nov 13, 2024

@WhyNotHugo You can disable this behavior by creating a type alias.

@mikea
Copy link

mikea commented Nov 21, 2024

Using Backtrace in errors requires a nightly compiler. This is mentioned in the readme.

Is there a fundamental reason for that? What doesn't work with 1.82.0?

Unfortunately using nightly compiler to ship production code is not the best approach for us. Would be great to have backtraces without provide.

@mikea
Copy link

mikea commented Nov 21, 2024

@mhnap could you provide more details which type alias is needed to use Backtrace with stable compiler?

@kornelski
Copy link
Contributor

Here's a workaround:

use std::backtrace::Backtrace as MacrosCannotSeeTypes;

#[derive(Debug, thiserror::Error)]
pub struct Error {
    backtrace: MacrosCannotSeeTypes,
}

@mikea
Copy link

mikea commented Nov 21, 2024

@kornelski that doesn't work:

use std::backtrace::Backtrace as StdBacktrace;

#[derive(Error, Debug)]
pub enum SetupError {
    #[error("error {source:?} {backtrace}")]
    Errno{
        #[from] source: nix::errno::Errno,
        backtrace: StdBacktrace,
    },
 }

gives me:

error: deriving From requires no fields other than source and backtrace
    --> src/rust/sentry-handler/lib.rs:1268:9
     |
1268 |         #[from] source: nix::errno::Errno,
     |         ^^^^^^^

@mhnap
Copy link

mhnap commented Nov 21, 2024

@mikea You can write From impl manually.

 impl From <nix::errno::Errno> for SetupError {
    fn from(value: nix::errno::Errno) -> Self {
        todo!()
    }
 }

@mikea
Copy link

mikea commented Nov 21, 2024

@mhnap I could, but what's preventing thiserror from generating the same code? It doesn't involve nightly or any obscure feature.

Also, your suggestion more or less means not to use thiserror when Backtrace is needed and to write everything manually.

@mhnap
Copy link

mhnap commented Nov 22, 2024

@mikea Because thiserror doesn't know how to generate From impl when there are custom fields other than source and backtrace.

@mikea
Copy link

mikea commented Nov 22, 2024

@mhnap maybe I am missing something, but this issue is precisely about that: generate From for two fields: source and backtrace. I am not asking to handle unknown fields: the original reporter (and me) would like to use Backtraces with stable rust.

It is not clear to me from these explanations why it is not possible to generate such code if I can write it manually.

I completely understand if the situation was "we agree, it would be better, but we don't have time. PRs are welcome". Or "we think this is wrong to do because X".

The answer instead was "it is documented". Or "do not use thiserror". Which is a little bit hostile for such a simple feature request, don't you think? Especially since Backtraces were stabilizing long long ago.

@mhnap
Copy link

mhnap commented Nov 22, 2024

@mikea In such a case this makes sense. If you find this usefull, I think it would be better to create a new issue (if there are no existing or closed ones with explanations) and explicitly write about a feature request to support the generation of the From impl with Backtrace on stable Rust.

(I'm not a contributor, I just noticed a couple of unanswered questions and decided to answer)

By the way, I bumped into this some time ago, but I also needed to use std::panic::Location so I still ended up with a manual From impl (and also I've created #316 for another feature request).

@mikea
Copy link

mikea commented Nov 22, 2024

@mhnap Sure, if you think it is helpful, here it is: #390

I was vary to create a new one, since this one already exist and quite to a point. Let's hope the new one will work better.

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

5 participants