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

Confusing error when providing the wrong type to be decoded #298

Closed
chevdor opened this issue May 3, 2021 · 3 comments
Closed

Confusing error when providing the wrong type to be decoded #298

chevdor opened this issue May 3, 2021 · 3 comments

Comments

@chevdor
Copy link
Contributor

chevdor commented May 3, 2021

The following fails:

use jsonrpsee::http_client::{traits::Client, HttpClientBuilder, JsonValue, Error};
use std::env;
use tokio::runtime::Runtime;

fn get_http_node() -> String {
	env::var("POLKADOT_HTTP").unwrap_or("http://localhost:9933".to_string())
}

fn main() {
	let url = String::from(get_http_node());
	println!("Connecting to {:?}", &url);
	let code = JsonValue::from("0x3a636f6465"); // :code in hex
	let params = vec![code.into()];

	let rt = Runtime::new().unwrap();
	let client = HttpClientBuilder::default().build(url).expect("Building client");
	let response: Result<Vec<u8>, _> = rt.block_on(client.request("state_getStorage", params.into()));
	println!("response: {:?}", response);

	assert!(response.unwrap().len() > 0);
}

with:

response: Err(ParseError(Error("missing field `error`", line: 1, column: 3752798)))
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseError(Error("missing field `error`", line: 1, column: 3752798))', examples/http-polkadot.rs:51:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Debugging the request, I see that we get a big answer from the node.
So I assume the request is sent properly and we get the answer. Decoding however fails at https://github.com/paritytech/jsonrpsee/blob/master/http-client/src/client.rs#L76

@chevdor chevdor changed the title Fail decoding response from a polkadot node Confusing error when providing the wrong type to be decoded May 3, 2021
@chevdor
Copy link
Contributor Author

chevdor commented May 3, 2021

@niklasad1 thanks for the hints.

Using the following does not solve the issue but does the trick:

let response: Result<String, _> = rt.block_on(client.request("state_getStorage", params.into()));

@jsdw
Copy link
Collaborator

jsdw commented Aug 17, 2022

This will hopefully be closed by #853

@niklasad1
Copy link
Member

Closed by #853

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

No branches or pull requests

3 participants