From 94e5fb7220e99dcb97197ac8a6b860dc2e80edc4 Mon Sep 17 00:00:00 2001 From: bingryan Date: Tue, 12 Mar 2024 18:19:07 +0800 Subject: [PATCH 1/8] refactor: better error message with without server running --- src/wallet.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/wallet.rs b/src/wallet.rs index 88a0ea2541..8627c6f35a 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -109,10 +109,21 @@ impl Wallet { if !no_sync { for i in 0.. { let response = async_ord_client.get("/blockcount").await?; - if response.text().await?.parse::().unwrap() >= chain_block_count { - break; - } else if i == 20 { - bail!("wallet failed to synchronize with ord server"); + + if let Ok(parsed_value) = response.text().await?.parse::() { + if parsed_value >= chain_block_count { + break; + } + } else { + eprintln!( + "wallet failed to request with the `ord server` after {} times", + i + ); + if i == 20 { + bail!( + "wallet failed to request with the `ord server`, make sure `ord server` is started !!!" + ); + } } tokio::time::sleep(Duration::from_millis(50)).await; } From a60fc9cdd0ff24a59dc9ea0ff2956d5e102f1e7c Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 12 Mar 2024 22:41:20 -0700 Subject: [PATCH 2/8] Amend --- src/wallet.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/wallet.rs b/src/wallet.rs index 8627c6f35a..9244a62a4d 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -114,16 +114,10 @@ impl Wallet { if parsed_value >= chain_block_count { break; } - } else { - eprintln!( - "wallet failed to request with the `ord server` after {} times", - i + } else if i == 20 { + bail!( + "wallet failed to synchronize with the server. Make sure `ord server` is running." ); - if i == 20 { - bail!( - "wallet failed to request with the `ord server`, make sure `ord server` is started !!!" - ); - } } tokio::time::sleep(Duration::from_millis(50)).await; } From 19b7f4bd46ef1f86f7121a2c0f679fec378160bb Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 12 Mar 2024 22:42:00 -0700 Subject: [PATCH 3/8] Amend --- src/wallet.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/wallet.rs b/src/wallet.rs index 9244a62a4d..4bf35384b3 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -110,10 +110,8 @@ impl Wallet { for i in 0.. { let response = async_ord_client.get("/blockcount").await?; - if let Ok(parsed_value) = response.text().await?.parse::() { - if parsed_value >= chain_block_count { - break; - } + if response.text().await?.parse::().unwrap() >= chain_block_count { + break; } else if i == 20 { bail!( "wallet failed to synchronize with the server. Make sure `ord server` is running." From ed49b020f7ea3a2c3bea45477449916814e12b27 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 12 Mar 2024 22:42:28 -0700 Subject: [PATCH 4/8] Amend --- src/wallet.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wallet.rs b/src/wallet.rs index 4bf35384b3..62cba07363 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -109,7 +109,6 @@ impl Wallet { if !no_sync { for i in 0.. { let response = async_ord_client.get("/blockcount").await?; - if response.text().await?.parse::().unwrap() >= chain_block_count { break; } else if i == 20 { From 68cab9e1badb2722505eda851aca5a3a761af565 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 12 Mar 2024 22:43:47 -0700 Subject: [PATCH 5/8] Amend --- src/wallet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet.rs b/src/wallet.rs index 62cba07363..047fea2a39 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -113,7 +113,7 @@ impl Wallet { break; } else if i == 20 { bail!( - "wallet failed to synchronize with the server. Make sure `ord server` is running." + "wallet failed to synchronize with the ord server. Make sure `ord server` is running." ); } tokio::time::sleep(Duration::from_millis(50)).await; From fa83eb66a2a8e8c147eab9d94b2f9ba10ff8d8d2 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 12 Mar 2024 22:49:00 -0700 Subject: [PATCH 6/8] Amend --- src/wallet.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/wallet.rs b/src/wallet.rs index 047fea2a39..8e98568af6 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -109,12 +109,16 @@ impl Wallet { if !no_sync { for i in 0.. { let response = async_ord_client.get("/blockcount").await?; - if response.text().await?.parse::().unwrap() >= chain_block_count { + if response + .text() + .await? + .parse::() + .expect("wallet failed to talk to server. Make sure `ord server` is running") + >= chain_block_count + { break; } else if i == 20 { - bail!( - "wallet failed to synchronize with the ord server. Make sure `ord server` is running." - ); + bail!("wallet failed to synchronize with `ord server`"); } tokio::time::sleep(Duration::from_millis(50)).await; } From 16ce8481d8cafb0d65090b10106d731b4b1769c6 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 12 Mar 2024 22:49:43 -0700 Subject: [PATCH 7/8] Amend --- src/wallet.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet.rs b/src/wallet.rs index 8e98568af6..d279b18d27 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -113,12 +113,12 @@ impl Wallet { .text() .await? .parse::() - .expect("wallet failed to talk to server. Make sure `ord server` is running") + .expect("wallet failed to talk to server. Make sure `ord server` is running.") >= chain_block_count { break; } else if i == 20 { - bail!("wallet failed to synchronize with `ord server`"); + bail!("wallet failed to synchronize with `ord server` after {i} attempts"); } tokio::time::sleep(Duration::from_millis(50)).await; } From bd37c4457884f8efce6a93b71fcaabd2459ba248 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 12 Mar 2024 22:55:40 -0700 Subject: [PATCH 8/8] Amend --- tests/wallet/balance.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/wallet/balance.rs b/tests/wallet/balance.rs index 120029a895..d7d3e626b2 100644 --- a/tests/wallet/balance.rs +++ b/tests/wallet/balance.rs @@ -146,7 +146,7 @@ fn unsynced_wallet_fails_with_unindexed_output() { .ord_rpc_server(&no_sync_ord_rpc_server) .bitcoin_rpc_server(&bitcoin_rpc_server) .expected_exit_code(1) - .expected_stderr("error: wallet failed to synchronize with ord server\n") + .expected_stderr("error: wallet failed to synchronize with `ord server` after 20 attempts\n") .run_and_extract_stdout(); CommandBuilder::new("wallet --no-sync balance")