-
Notifications
You must be signed in to change notification settings - Fork 172
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
[servers] return error if context or params fails #295
Conversation
0c88db6
to
0bfa1ff
Compare
@@ -35,16 +38,17 @@ impl RpcModule { | |||
pub fn register_method<F, R>(&mut self, method_name: &'static str, callback: F) -> Result<(), Error> | |||
where | |||
R: Serialize, | |||
F: RpcMethod<R>, | |||
F: RpcMethod<R, InvalidParams>, |
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.
Should we do something like dyn Error
here instead? Or implement our own error trait that gives us the JSON-RPC error code along with the message?
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.
Or implement our own error trait that gives us the JSON-RPC error code along with the message?
That sounds neat and I like, but it might be annoying users to explicitly implement that trait for the error types that they "plug-in" in Error::ContextFailed(user err)
? However, it would be a way for the users to explicitly add there own error codes for this
For methods without context
this would work very nicely.
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.
Let's create an issue for this and address it another PR
@@ -16,12 +16,36 @@ impl<T: fmt::Display> fmt::Display for Mismatch<T> { | |||
} | |||
} | |||
|
|||
/// Invalid params. | |||
#[derive(Debug)] | |||
pub struct InvalidParams; |
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.
I don't understand why we need this zst, i.e. why the ServerCallError::InvalidParams
variant needs an unnamed field. I'll read more and perhaps I'll figure it out.
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.
It was just that register_method_without_context
can only fail when the params couldn't be parsed so it was introduced to avoid matching on unreachable enum variants
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.
Let's get this in, just fix up the naming. Still a bit unsure about how the errors will work out in practice but this is better than what we had so let's merge it.
This PR changes the servers behavior when they get a response with params or user provided context that fails.
Instead of just terminating the connection we now return back a
JSON-RPC error
.I changed the
RpcMethod trait
to take an generic Error instead such that we can configure it statically instead of matching of the entire enum when the is just one or two possible errors.