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?
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. 馃榿
Most helpful comment
This is because
async_graphql::Errordoesn't implement theErrortrait. This is an intentional design decision, asasync_graphql::Erroris a GraphQL-specific error and shouldn't be used as a general error. You can use formatmessagefield of theErrorif you like, which is aString. Can you give more details about your use case?