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

Unresolved import 'thiserror' when adding a Backtrace to an enum struct #236

Closed
JustAnotherCodemonkey opened this issue Jun 13, 2023 · 7 comments

Comments

@JustAnotherCodemonkey
Copy link

JustAnotherCodemonkey commented Jun 13, 2023

Error happens when I add a backtrace to an enum variant as is shown in the docs. Interestingly, I get a different error when I add #[from] while I have the backtrace in there. Might be a different issue but I can include it if asked for. I guess I'm just thinking go with the more basic issue first.

Edit: Sorry I made this at like 1:00am I forgot to add some important details: MacOS, tried on both latest stable and nightly, building both for x86_64 macos and wasm32-unknown-unknown.

code:

#[derive(Debug, Error)]
pub enum AppError {
    #[error("{source}")]
    RenderError {
        #[source]
        source: RenderError,
        backtrace: Backtrace,
    },
}

#[derive(Debug, Error)]
pub enum RenderError {
    #[error("Could not set up game canvas.")]
    SetupCanvasFailure(
        #[source]
        #[from]
        SetupCanvasFailure,
    ),
    #[error("Could not create surface from window {window_debug}.")]
    SurfaceCreationFailure {
        #[source]
        error: wgpu::CreateSurfaceError,
        window_debug: String,
    },
    #[error("Could not get adapter with options {options_debug}.")]
    GetAdapterFailure { options_debug: String },
    #[error("Could not get device with descriptor {descriptor_debug}.")]
    GetDeviceFailure {
        #[source]
        error: wgpu::RequestDeviceError,
        descriptor_debug: String,
    },
    #[error("The surface {surface_debug} with adapter {adapter_debug} \
    did not support any of the formats supported by the app.")]
    NoSupportedSurfaceFormats {
        surface_debug: String,
        adapter_debug: String,
    },
    #[error("The surface (with capabilities {surface_capabilities_debug}) \
    did not support post-multiplied alpha compositing which is an assumption \
    made for the game.")]
    PostMultipliedAlphaUnsupported { surface_capabilities_debug: String },
}

error:

error[E0432]: unresolved import `thiserror`
  --> src/app.rs:38:17
   |
38 | #[derive(Debug, Error)]
   |                 ^^^^^ no `ThiserrorProvide` in `__private`
   |
   = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unused import: `std::error::Error`
 --> src/app.rs:6:5
  |
6 | use std::error::Error;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

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

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

error[E0277]: `?` couldn't convert the error to `AppError`
  --> src/app.rs:20:71
   |
20 |         let graphics_context = GraphicsContext::new(&event_loop).await?;
   |                                                                       ^ the trait `From<RenderError>` is not implemented for `AppError`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
   = help: the following other types implement trait `FromResidual<R>`:
             <Result<T, F> as FromResidual<Result<Infallible, E>>>
             <Result<T, F> as FromResidual<Yeet<E>>>
   = note: required for `Result<App, AppError>` to implement `FromResidual<Result<Infallible, RenderError>>`

error[E0599]: no method named `thiserror_provide` found for reference `&RenderError` in the current scope
  --> src/app.rs:43:9
   |
43 |         source: RenderError,
   |         ^^^^^^ method not found in `&RenderError`
@istudyatuni
Copy link

#204 looks similar

@JustAnotherCodemonkey
Copy link
Author

Ok I didn't realize that Backtrace wasn't fully stable. Both the thiserror and std docs very much seem to imply otherwise. There should definitely be a warning in the thiserror docs about this and maybe thiserror could handle this more gracefully.

(that last part is why I'll keep this open for now.)

@rollo-b2c2
Copy link

Both the thiserror and std docs very much seem to imply otherwise

They really do.

@juancampa
Copy link

juancampa commented Sep 21, 2023

Is there a work-around for this other than downgrading nightly versions or removing the Backtrace from the enum altogether?

@JustAnotherCodemonkey
Copy link
Author

I was kind of just thinking of including some sort of temporary check to make sure that the user is using nightly just to make a friendlier message if it blows up, just anything but the error that I got. In any case, since I don't really see a good way to do that and hopefully this should all go away anyways when Backtrace gets stabilized, I might just close this.

@juancampa
Copy link

juancampa commented Sep 21, 2023

Is this really about backtrace being stable? I thought this started happening because #![feature(provide_any)] was rejected and thus removed from nightly. But honestly, I'm pretty confused.

@JustAnotherCodemonkey
Copy link
Author

Huh, I don't really see what that would have to do with this.

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