From 2c210115c5cc9c89e55e07bf49b6aec012899015 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Thu, 12 Mar 2020 16:09:00 -0600 Subject: [PATCH] CLI/Keygen - fix shell return value on error --- Cargo.lock | 1 + cli/src/main.rs | 14 +++++++++++++- keygen/Cargo.toml | 1 + keygen/src/keygen.rs | 14 +++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce3ac9ea98c7f4..816a540d06c202 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4130,6 +4130,7 @@ dependencies = [ "solana-cli-config 1.1.0", "solana-remote-wallet 1.1.0", "solana-sdk 1.1.0", + "thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-bip39 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/cli/src/main.rs b/cli/src/main.rs index df2ca0ea66d671..111eb6bbd5d6d6 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -231,7 +231,19 @@ fn main() -> Result<(), Box> { .get_matches(); if let Err(e) = do_main(&matches) { - eprintln!("error: {}", e); + use thiserror::Error; + + #[derive(Error)] + #[error("")] + struct PrettyError(String); + + impl std::fmt::Debug for PrettyError { + fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(fmt, "{}", self.0) + } + } + + return Err(PrettyError(e.to_string()).into()); } Ok(()) } diff --git a/keygen/Cargo.toml b/keygen/Cargo.toml index f828bcb6b04dd9..c8c659c57a8c29 100644 --- a/keygen/Cargo.toml +++ b/keygen/Cargo.toml @@ -17,6 +17,7 @@ solana-clap-utils = { path = "../clap-utils", version = "1.1.0" } solana-cli-config = { path = "../cli-config", version = "1.1.0" } solana-remote-wallet = { path = "../remote-wallet", version = "1.1.0" } solana-sdk = { path = "../sdk", version = "1.1.0" } +thiserror = "1.0.11" tiny-bip39 = "0.7.0" [[bin]] diff --git a/keygen/src/keygen.rs b/keygen/src/keygen.rs index 0f6b710469c4be..7028a686772888 100644 --- a/keygen/src/keygen.rs +++ b/keygen/src/keygen.rs @@ -193,7 +193,19 @@ fn grind_parse_args( fn main() -> Result<(), Box> { let result = do_main().err(); if let Some(err) = result { - eprintln!("hi! {}", err); + use thiserror::Error; + + #[derive(Error)] + #[error("")] + struct PrettyError(String); + + impl std::fmt::Debug for PrettyError { + fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(fmt, "{}", self.0) + } + } + + return Err(PrettyError(err.to_string()).into()); } Ok(()) }