Skip to content

Commit

Permalink
Improve error messages related to cookie file (ordinals#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Feb 7, 2023
1 parent 2c6765b commit 0569e0b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ impl Options {
}

pub(crate) fn bitcoin_rpc_client(&self) -> Result<Client> {
let cookie_file = self.cookie_file()?;
let cookie_file = self
.cookie_file()
.map_err(|err| anyhow!("failed to get cookie file path: {err}"))?;

let rpc_url = self.rpc_url();

Expand All @@ -139,8 +141,13 @@ impl Options {
cookie_file.display()
);

let client = Client::new(&rpc_url, Auth::CookieFile(cookie_file))
.with_context(|| format!("failed to connect to Bitcoin Core RPC at {rpc_url}"))?;
let client =
Client::new(&rpc_url, Auth::CookieFile(cookie_file.clone())).with_context(|| {
format!(
"failed to connect to Bitcoin Core RPC at {rpc_url} using cookie file {}",
cookie_file.display()
)
})?;

let rpc_chain = match client.get_blockchain_info()?.chain.as_str() {
"main" => Chain::Mainnet,
Expand Down

0 comments on commit 0569e0b

Please sign in to comment.