-
Notifications
You must be signed in to change notification settings - Fork 433
Implement std::error::Error
for all error types
#419
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Not sure why you are getting that error.
Since FieldError has a Not sure what's the best way around that, I'll have a look at the code. |
From https://www.reddit.com/r/rust/comments/9amj6w/hey_rustaceans_got_an_easy_question_ask_here/e59n3n5/:
|
I never was a big fan of the We could think about removing it, and only having a |
@theduke I like that. Since thats a breaking change do we have to go through a round of deprecation or is it fine? |
Nah let's batch it together with the other changes related to async/await and removing the old macros. What's the status here, did you implement the FieldError? |
I had totally forgotten about this. I'll give it another look soon. |
Sorry for the delay but this should be ready for next review. I had to make a few changes to get |
This is required for implementing `Display` for `FieldError`
This required removing `impl From<T> for FieldError where T: Display` because it would otherwise cause a conflicting implementation. That is because `impl From<T> for T` already exists. Instead I added `impl From<String> for FieldError` and `impl From<&str> for FieldError` which should cover most use cases of the previous `impl`. I also added `FieldError::from_error` so users can convert from any error they may have.
Codecov Report
@@ Coverage Diff @@
## master #419 +/- ##
==========================================
- Coverage 85.74% 85.74% -0.01%
==========================================
Files 110 111 +1
Lines 15933 15982 +49
==========================================
+ Hits 13661 13703 +42
- Misses 2272 2279 +7
Continue to review full report at Codecov.
|
This seems to be missing a We need that more than a the |
I did try adding
It seems that you cannot both implement use std::fmt::{Formatter, self, Display};
#[derive(Debug)]
struct MyError(String);
impl std::error::Error for MyError {}
impl Display for MyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}
impl<T: std::error::Error> From<T> for MyError {
fn from(s: T) -> Self {
unimplemented!()
}
} That fails to compile with the same error. That is why I added pub fn from_error<E>(error: E) -> FieldError<S>
where
E: std::error::Error,
{
FieldError::from(error.to_string())
} Was the only working solution I could think of. |
Does it make sense to not implement std::error::Error for FieldError because of this? I’m thinking it’s pretty inconvenient 🤔 |
Ah yeah I forgot about the coherence rules. You cant both implement Yeah let's just drop the impl on FieldError. It doesn't really matter anyway since it is not a type users work with directly. |
Alright cool. I’ll revert it tomorrow. Does it make sense to keep the Display impl for Value? |
We cannot have this and `impl<S> std::error::Error for FieldError<S>` so we agreed this is more valuable. More context graphql-rust#419
I have brought back Guess this should be good now 😊 |
I have some additional changes. Will push tomorrow. |
@theduke Anything I can help out with? |
@davidpdrsn Is there anything more to go in on this PR? juniper is the last holdout in my app before I can simply |
@jkoudys No it should be good to go. I wonder which error you're having to convert into Also note that as per the discussions above you wont be able to convert |
Trying to into a |
I think proper implementation of std::error::Error should include implementation of |
@andy128k you mean like on the GraphQLError itself, to give a simple mapping back to the original error type? e.g. impl<'a> std::error::Error for GraphQLError<'a> {
fn source(&self) -> Option<&(dyn Error + 'a)> {
Some(&self)
}
} Can't think what else we'd need, unless you mean It's been 4 months.... |
This PR has been blocked by all async-flux. That seems to have settled now so I do hope to get it merged soon. |
@LegNeato master still doesn't build due to some async stuff it seems. Should I merge this into the async branch instead? |
Everything on master except the book builds / passes? |
If I clone a fresh copy of the repo and run
|
@davidpdrsn yeah weirdly just doing |
Thanks for merging! |
Fixes #415
I'm having some issues with
FieldError
. I end up hitting a conflicting implementation error when I addI get this error:
I'm not quite sure what is causing that.