-
Notifications
You must be signed in to change notification settings - Fork 178
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
Propagate cause of InvalidParams
#463
Conversation
Log more when params parsing fails
@@ -48,7 +48,7 @@ impl<T: fmt::Display> fmt::Display for Mismatch<T> { | |||
pub enum CallError { | |||
/// Invalid params in the call. | |||
#[error("Invalid params in the call")] | |||
InvalidParams, | |||
InvalidParams(#[source] anyhow::Error), |
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.
This looks good
Co-authored-by: Niklas Adolfsson <[email protected]>
…rpsee into dp-debug-substrate-tests
pub trait ToRpcParams: Serialize { | ||
/// Serialized the type as a JSON array. | ||
/// Serialize the type as a JSON array. |
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.
👍
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.
LGTM expect that I think the proc macro API
test should be moved into integration tests but feel free to convince me :)
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.
Looks good, you can turn some runtime concats into compile time concats :)
Co-authored-by: Maciej Hirsz <[email protected]>
…ch/jsonrpsee into dp-invalid-params-carries-error
I think it is a unit test of the |
@@ -110,7 +110,7 @@ macro_rules! array_impls { | |||
} | |||
|
|||
array_impls! { | |||
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |||
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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.
This is kind of a tangent, but we could just use const generics now that they are available instead of the macro:
impl<P: Serialize, const N: usize> ToRpcParams for [P; N] {}
Edit: not sure if that works if serde isn't using const generics for arrays yet (and it looks like they don't?), might need an extra bound where [P; N]: Serialize
.
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.
The problem I think is that serde impls Serialize
for [T; 0] .... [T; 32]
and impl<P: Serialize, const N: usize> ToRpcParams for [P; N]
for 0...usize::MAX?
but yeah I think your snippet should work
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.
@niklasad1 tried this and reported back that it doesn't work.
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.
ok, maybe we should open a PR to serde then?!
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.
impl<P, const N: usize> ToRpcParams for [P; N] where [P; N]: Serialize {}
Works for me
Change
CallError::InvalidParams
to carry the actual error (as ananyhow::Error
), enabling more descriptive errors for users.One doubt I'd like reviewers feedback on is adding the
#[source]
attribute toCallError::InvalidParams
. Not sure it's useful/correct.Based on #458, hence the noise.