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

Error message for invalid auth credentials could be more helpful #117

Open
chris-belcher opened this issue Jul 19, 2020 · 4 comments
Open

Comments

@chris-belcher
Copy link

chris-belcher commented Jul 19, 2020

This script uses an incorrect password:

extern crate bitcoincore_rpc;                                                   
use bitcoincore_rpc::{Client, Error, RpcApi, Auth};                             
                                                                                
fn main() -> Result<(), Error> {                                                
                                                                                
    let auth = Auth::UserPass(                                                  
        "regtest-username".to_string(),                                           
        "incorrect-password".to_string()                                           
    );                                                                          
    let rpc = Client::new("http://localhost:18443".to_string(), auth)?;         
                                                                                
    let info = rpc.get_blockchain_info()?;                                      
    println!("info = {:#?}", info);                                             
    println!("best block hash = {}", info.best_block_hash);                     
    Ok(())                                                                      
}

And it produces this error:

Error: JsonRpc(Json(Error("EOF while parsing a value", line: 1, column: 0)))

The error message doesn't mention anything about invalid credentials.

I think what's happening is Bitcoin Core is sending back a HTTP 401 Unauthorized reply, but the rust library still tries to read from the HTTP body. As there's no body it results in a confusing EOF error instead.

I may code a PR myself which fixes this by checking for 401 (I only just started learning rust so this may take a while)

@stevenroose
Copy link
Collaborator

That's a good point. We should use the HTTP header. But I'm not sure if this is something that would need to happen at the jsonrpc crate level.

@sgeisler
Copy link
Contributor

@stevenroose yeah, looks like it, jsonrpc ignores error codes.

@stevenroose
Copy link
Collaborator

Reading JSON-RPC spec, says

It is transport agnostic in that the concepts can be used within the same process, over sockets, over http, or in many various message passing environments.

So I don't think HTTP status codes are the correct way to handle errors server-side. It should be a 200 OK with a {"error": { ... }} to specify the error. So this is (per spec) a mistake on Core's side.

@stevenroose
Copy link
Collaborator

Well in fact I think the jsonrpc spec should return a special error like UnexpectedHttpStatus(u32) when it doesn't encounter 200 OK.

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