Async-graphql: async_graphql::Error and thiserror

Created on 20 Oct 2020  路  4Comments  路  Source: async-graphql/async-graphql

Since upgrading to async-graphql 2.0 i have kind of a problem with async_graphql::Error in combination with thiserror.

use thiserror::Error;
use async_graphql::{ErrorExtensions, FieldError};

#[derive(Error, Debug)]
pub enum CatalogError {
    #[error("Api error: {0}")]
    GraphQL(#[from] async_graphql::Error),
    #[error("Server error: {0}")]
    Server(String),
    #[error("Unknown server error")]
    Unknown,
}

the above code does not compile with the following errors:

error[E0599]: no method named `as_dyn_error` found for reference `&async_graphql::Error` in the current scope
   --> src\error.rs:9:13
    |
9   |     #[error("Api error: {0}")]
    |             ^^^^^^^^^^^^^^^^ method not found in `&async_graphql::Error`
    | 
   ::: ...\async-graphql\src\error.rs:171:1
    |
171 | pub struct Error {
    | ----------------
    | |
    | doesn't satisfy `_: thiserror::private::AsDynError`
    | doesn't satisfy `async_graphql::Error: std::error::Error`
    |
    = note: the method `as_dyn_error` exists but the following trait bounds were not satisfied:
            `async_graphql::Error: std::error::Error`
            which is required by `async_graphql::Error: thiserror::private::AsDynError`
            `&async_graphql::Error: std::error::Error`
            which is required by `&async_graphql::Error: thiserror::private::AsDynError`

error[E0599]: no method named `as_display` found for reference `&async_graphql::Error` in the current scope
   --> src\error.rs:9:13
    |
9   |     #[error("Api error: {0}")]
    |             ^^^^^^^^^^^^^^^^ method not found in `&async_graphql::Error`
    | 
   ::: ...\async-graphql\src\error.rs:171:1
    |
171 | pub struct Error {
    | ---------------- doesn't satisfy `async_graphql::Error: std::fmt::Display`
    |
    = note: the method `as_display` exists but the following trait bounds were not satisfied:
            `async_graphql::Error: std::fmt::Display`
            which is required by `&async_graphql::Error: thiserror::private::DisplayAsDisplay`

With the old version of async-graphql everything worked fine, so....i feel kinda dumb, but am i missing some kind of import or is this just not possible anymore?

question

Most helpful comment

This is because async_graphql::Error doesn't implement the Error trait. This is an intentional design decision, as async_graphql::Error is a GraphQL-specific error and shouldn't be used as a general error. You can use format message field of the Error if you like, which is a String. Can you give more details about your use case?

All 4 comments

Is this error obtained from Response::into_result()?

This is because async_graphql::Error doesn't implement the Error trait. This is an intentional design decision, as async_graphql::Error is a GraphQL-specific error and shouldn't be used as a general error. You can use format message field of the Error if you like, which is a String. Can you give more details about your use case?

I'm just beginning to implement the API, so the way i use errors is not really set. I just wanted to initally use and expose the errors throught he API for ease of development. So...for that i will use the message field and report back if i really need the Error trait and as such have a valid use case. Until then, everything is fine 馃憤 and thanks for clarifying.

I will close this issue, if you have any questions, please feel free to open it. 馃榿

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielSanchezQ picture danielSanchezQ  路  4Comments

AurelienFT picture AurelienFT  路  5Comments

Weasy666 picture Weasy666  路  4Comments

hapcode picture hapcode  路  3Comments

servonlewis picture servonlewis  路  4Comments