From 30a9c3db1e28a1ae80fc55de8804f1d73f2cef09 Mon Sep 17 00:00:00 2001 From: Simon B Date: Tue, 12 Dec 2017 05:56:48 +0100 Subject: [PATCH] Improve errors that confuse new users (#467) * Make Get coinbase via wallet API error more self-help friendly. Also show the wallet API URL that failed to respond. * spelling and rustfmt nit * more informational output from `grin server stop` * newcomer friendly error when wallet.seed isn't found * grin wallet (info|outputs): better error message --- src/bin/grin.rs | 13 ++++++++----- wallet/src/client.rs | 13 +++++++++---- wallet/src/info.rs | 8 ++++++-- wallet/src/outputs.rs | 6 +++++- wallet/src/types.rs | 6 ++++-- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/bin/grin.rs b/src/bin/grin.rs index fc6b6d33c..ff40391e3 100644 --- a/src/bin/grin.rs +++ b/src/bin/grin.rs @@ -356,15 +356,18 @@ fn server_command(server_args: &ArgMatches, global_config: GlobalConfig) { } }); match daemonize.start() { - Ok(_) => info!(LOGGER, "Grin server succesfully started."), + Ok(_) => info!(LOGGER, "Grin server successfully started."), Err(e) => error!(LOGGER, "Error starting: {}", e), } } - ("stop", _) => println!("TODO, just 'kill $pid' for now."), + ("stop", _) => println!("TODO. Just 'kill $pid' for now. Maybe /tmp/grin.pid is $pid"), (cmd, _) => { - println!(":: {:?}", server_args); - panic!("Unknown server command '{}', use 'grin help server' for details", cmd); - } + println!(":: {:?}", server_args); + panic!( + "Unknown server command '{}', use 'grin help server' for details", + cmd + ); + } } } diff --git a/wallet/src/client.rs b/wallet/src/client.rs index 8366cbcb5..4976a1f40 100644 --- a/wallet/src/client.rs +++ b/wallet/src/client.rs @@ -35,7 +35,8 @@ pub fn create_coinbase(url: &str, block_fees: &BlockFees) -> Result Result<(), Error req.set_body(json); let work = client.request(req); - let _ = core.run(work).and_then(|res|{ - if res.status()==hyper::StatusCode::Ok { + let _ = core.run(work).and_then(|res| { + if res.status() == hyper::StatusCode::Ok { info!(LOGGER, "Transaction sent successfully"); } else { - error!(LOGGER, "Error sending transaction - status: {}", res.status()); + error!( + LOGGER, + "Error sending transaction - status: {}", + res.status() + ); return Err(hyper::Error::Status); } Ok(()) diff --git a/wallet/src/info.rs b/wallet/src/info.rs index 64b8a7d1b..f9a36c80a 100644 --- a/wallet/src/info.rs +++ b/wallet/src/info.rs @@ -63,7 +63,7 @@ pub fn show_info(config: &WalletConfig, keychain: &Keychain) { writeln!(t, "{}", title).unwrap(); writeln!(t, "--------------------------").unwrap(); t.reset().unwrap(); - + let mut table = table!( [bFG->"Total", FG->amount_to_hr_string(unspent_total+unconfirmed_total)], [bFY->"Awaiting Confirmation", FY->amount_to_hr_string(unconfirmed_total)], @@ -78,6 +78,10 @@ pub fn show_info(config: &WalletConfig, keychain: &Keychain) { }); if let Err(_) = result { - println!("WARNING - Showing local data only - Wallet was unable to contact a node to update and verify the info shown here."); + println!( + "\nWARNING: Wallet failed to verify data. \ + The above is from local cache and possibly invalid! \ + (is your `grin server` offline or broken?)" + ); } } diff --git a/wallet/src/outputs.rs b/wallet/src/outputs.rs index 60fa3d037..070cf3629 100644 --- a/wallet/src/outputs.rs +++ b/wallet/src/outputs.rs @@ -93,6 +93,10 @@ pub fn show_outputs(config: &WalletConfig, keychain: &Keychain, show_spent:bool) }); if let Err(_) = result { - println!("WARNING - Showing local data only - Wallet was unable to contact a node to update and verify the outputs shown here."); + println!( + "\nWARNING: Wallet failed to verify data. \ + The above is from local cache and possibly invalid! \ + (is your `grin server` offline or broken?)" + ); } } diff --git a/wallet/src/types.rs b/wallet/src/types.rs index 1e9701513..dd274173c 100644 --- a/wallet/src/types.rs +++ b/wallet/src/types.rs @@ -354,7 +354,10 @@ impl WalletSeed { LOGGER, "Run: \"grin wallet init\" to initialize a new wallet.", ); - panic!("wallet seed file does not yet exist (grin wallet init)"); + panic!(format!( + "wallet seed file {} could not be opened (grin wallet init)", + seed_file_path + )); } } } @@ -522,7 +525,6 @@ impl WalletData { max_outputs: usize, default_strategy: bool, ) -> Vec { - // first find all eligible outputs based on number of confirmations let mut eligible = self.outputs .values()