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

Switch from anyhow::Result to std Result #333

Merged
merged 4 commits into from
May 24, 2021
Merged

Conversation

dvdplm
Copy link
Contributor

@dvdplm dvdplm commented May 24, 2021

Don't return anyhow::Resultand instead just use thiserror and standard Result<T, Error> where Error is the jsonrpsee_types::error::Error type.

The downside is that with this PR jsonrpsee_types depends on both soketto and hyper. I think making jsonrpsee_types as dependency-free as possible was a big part of an external crate in the first place. OTOH all users will depend on at least one of them.

@dvdplm dvdplm requested review from maciejhirsz and niklasad1 May 24, 2021 10:38
tokio::spawn(async move { server.start().await });
addr
Ok(addr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch.

@@ -18,3 +18,7 @@ log = { version = "0.4", default-features = false }
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = { version = "1", default-features = false, features = ["alloc", "raw_value", "std"] }
thiserror = "1.0"
# TODO: a bit sad to have to pull in soketto to handle errors
soketto = "0.4"
Copy link
Member

@niklasad1 niklasad1 May 24, 2021

Choose a reason for hiding this comment

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

yeah, I don't know how handle those without removing the shared error type.

but maybe a good idea to kill the big error type and that each crates has to define their own error type in another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Won't that make it tricky to share code between the servers?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, unless you come up with super nice generic error type that both can use but then you need some extra boiler-plate.

Like map.err(|e| Error::Transport(Box::new(e))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't think of a better way other than adding features, which I'm not sure is such a good idea.

Copy link
Member

Choose a reason for hiding this comment

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

ok, you mean making soketto and hyper optional dependencies?

That's ok but why not let each crate implement implement the From<TransportError> for Error?
Then we shouldn't bring in any extra dependencies but a little bit of "redundant code", like for client/server as long they use the same transport library

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hat's ok but why not let each crate implement implement the From<TransportError> for Error?
Then we shouldn't bring in any extra dependencies but a little bit of "redundant code", like for client/server as long they use the same transport library

#334

@dvdplm dvdplm merged commit bfe1582 into master May 24, 2021
@dvdplm dvdplm deleted the dp-switch-to-thiserror branch May 24, 2021 11:25
@@ -130,7 +130,8 @@ impl RpcModule {
self.methods.insert(
unsubscribe_method_name,
Box::new(move |id, params, tx, conn| {
let sub_id = params.one().map_err(|e| anyhow::anyhow!("{:?}", e))?;
// let sub_id = params.one().map_err(|e| anyhow::anyhow!("{:?}", e))?;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// let sub_id = params.one().map_err(|e| anyhow::anyhow!("{:?}", e))?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad. Fixed this one in #334

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