You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[rpc(server, client, namespace = "myrpc")]pubtraitMyRpc{// an explicit error for this method#[method(name = "myMethod1")]asyncfnmy_method1(&self) -> Result<MyData1,MyError1>;// an explicit error for this method#[method(name = "myMethod2")]asyncfnmy_method2(&self) -> Result<MyData2,MyError2>;// backward-compatible generic error for this method#[method(name = "myMethod3")]asyncfnmy_method3(&self) -> Result<MyData3, jsonrpsee::core::Error>;}pubenumMyError1{// some variants here}pubenumMyError2{// some variants here}implFrom<MyError1>for jsonrpsee::core::Error{fnfrom(val:MyError1) -> jsonrpsee::core::Error{// my custom implementation for this method's errors
jsonrpsee::core::Error::Other(ErrorObjectOwned{/* ... */}}}}implFrom<MyError2>for jsonrpsee::core::Error{fnfrom(val:MyError2) -> jsonrpsee::core::Error{// my custom implementation for this method's errors
jsonrpsee::core::Error::Other(ErrorObjectOwned{/* ... */}}}}
The idea here is to allow methods to return an error type that can be converted into jsonrpsee::core::Error instead of requiring it explicitly.
This would allow us to have type-safe and clearly expressed application-level errors for the RPC calls - something we have had trouble with for quite some time.
We want to supply the data for certain errors, and our current implementation is a mess; people tend to manually construct the jsonrpsee::core::Error instead of going through the helper functions (which are not really discoverable, at least not in a way the type-safe errors enable).
Our frontend guys are also complaining it's hard to understand all possible application-level error cases as the code evolves, and we figured having an explicit error enum for every method would work very well for us.
This can be implemented in a backward-compatible way if the error is made to be impl Into<jsonrpsee::core::Error> instead of an explicit jsonrpsee::core::Error.
Alternatively, Into<jsonrpsee::types:error::ErrorObjectOwned> could be used - this is more direct, but doesn't allow invoking the baked-in errors, which is kind of a limitation.
This does not make much sense from the client-side perspective, so I propose the client trait to rewrite the errors to still be jsonrpsee::core::Error.
The text was updated successfully, but these errors were encountered:
I'd like to do something like this:
The idea here is to allow methods to return an error type that can be converted into
jsonrpsee::core::Error
instead of requiring it explicitly.This would allow us to have type-safe and clearly expressed application-level errors for the RPC calls - something we have had trouble with for quite some time.
We want to supply the data for certain errors, and our current implementation is a mess; people tend to manually construct the
jsonrpsee::core::Error
instead of going through the helper functions (which are not really discoverable, at least not in a way the type-safe errors enable).Our frontend guys are also complaining it's hard to understand all possible application-level error cases as the code evolves, and we figured having an explicit error enum for every method would work very well for us.
This can be implemented in a backward-compatible way if the error is made to be
impl Into<jsonrpsee::core::Error>
instead of an explicitjsonrpsee::core::Error
.Alternatively,
Into<jsonrpsee::types:error::ErrorObjectOwned>
could be used - this is more direct, but doesn't allow invoking the baked-in errors, which is kind of a limitation.This does not make much sense from the client-side perspective, so I propose the client trait to rewrite the errors to still be
jsonrpsee::core::Error
.The text was updated successfully, but these errors were encountered: