Skip to content
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

Merged
merged 48 commits into from
Sep 14, 2021
Merged

Conversation

dvdplm
Copy link
Contributor

@dvdplm dvdplm commented Sep 11, 2021

Change CallError::InvalidParams to carry the actual error (as an anyhow::Error), enabling more descriptive errors for users.

One doubt I'd like reviewers feedback on is adding the #[source] attribute to CallError::InvalidParams. Not sure it's useful/correct.

Based on #458, hence the noise.

@@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good

utils/Cargo.toml Outdated Show resolved Hide resolved
pub trait ToRpcParams: Serialize {
/// Serialized the type as a JSON array.
/// Serialize the type as a JSON array.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@niklasad1 niklasad1 left a 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 :)

Copy link
Contributor

@maciejhirsz maciejhirsz left a 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 :)

proc-macros/src/render_server.rs Outdated Show resolved Hide resolved
proc-macros/src/render_server.rs Outdated Show resolved Hide resolved
@dvdplm
Copy link
Contributor Author

dvdplm commented Sep 14, 2021

I think the proc macro API test should be moved into integration tests but feel free to convince me :)

I think it is a unit test of the call_with and call methods. You're right that the setup is big-ish but it is just setup, no asserting on the correctness or not of the macro generated code.

@@ -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
Copy link
Contributor

@maciejhirsz maciejhirsz Sep 14, 2021

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.

Copy link
Member

@niklasad1 niklasad1 Sep 14, 2021

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

Copy link
Contributor Author

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.

Copy link
Member

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?!

Copy link
Contributor

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

@dvdplm dvdplm merged commit b16568b into master Sep 14, 2021
@dvdplm dvdplm deleted the dp-invalid-params-carries-error branch September 14, 2021 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants