Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
make errors prettier and fix issue #57 (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravidio authored Jan 25, 2019
1 parent 8dffe6f commit 0e092a7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 51 deletions.
98 changes: 49 additions & 49 deletions src/common/error_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,102 @@ use grin_core::libtx;

#[derive(Clone, Eq, PartialEq, Debug, Fail)]
pub enum ErrorKind {
#[fail(display = "secp error")]
#[fail(display = "\x1b[31;1merror:\x1b[0m secp error")]
Secp,
#[fail(display = "model not found!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m model not found!")]
ModelNotFound,
#[fail(display = "error opening wallet!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m error opening wallet!")]
OpenWalletError,
#[fail(display = "error deriving keychain!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m error deriving keychain!")]
DeriveKeychainError,
#[fail(display = "wallet should be empty before attempting restore!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m wallet should be empty before attempting restore!")]
WalletShouldBeEmpty,
#[fail(display = "transaction with slate id {} already received!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m transaction with slate id {} already received!", 0)]
TransactionAlreadyReceived(String),
#[fail(display = "transaction with slate id {} does not exist!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m transaction with slate id {} does not exist!", 0)]
TransactionDoesntExist(String),
#[fail(display = "transaction with slate id {} can not be cancelled!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m transaction with slate id {} can not be cancelled!", 0)]
TransactionNotCancellable(String),
#[fail(display = "transaction cancellation error: {}", _0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m transaction cancellation error: {}", _0)]
TransactionCancellationError(&'static str),
#[fail(display = "internal transaction error!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m internal transaction error!")]
LibTX(libtx::ErrorKind),
#[fail(display = "Not enough funds. Required: {}, Available: {}", needed_disp, available_disp)]
#[fail(display = "\x1b[31;1merror:\x1b[0m Not enough funds. Required: {}, Available: {}", needed_disp, available_disp)]
NotEnoughFunds { available: u64, available_disp: String, needed: u64, needed_disp: String },
#[fail(display = "Account label {} already exists!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m Account label {} already exists!", 0)]
AccountLabelAlreadyExists(String),
#[fail(display = "invalid transaction id given: `{}`", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m invalid transaction id given: `{}`", 0)]
InvalidTxId(String),
#[fail(display = "invalid amount given: `{}`", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m invalid amount given: `{}`", 0)]
InvalidAmount(String),
#[fail(display = "invalid selection strategy, use either 'smallest' or 'all'")]
#[fail(display = "\x1b[31;1merror:\x1b[0m invalid selection strategy, use either 'smallest' or 'all'")]
InvalidStrategy,
#[fail(display = "invalid number of minimum confirmations given: `{}`", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m invalid number of minimum confirmations given: `{}`", 0)]
InvalidMinConfirmations(String),
#[fail(display = "invalid number of outputs given: `{}`", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m invalid number of outputs given: `{}`", 0)]
InvalidNumOutputs(String),
#[fail(display = "could not unlock wallet! are you using the correct passphrase?")]
#[fail(display = "\x1b[31;1merror:\x1b[0m could not unlock wallet! are you using the correct passphrase?")]
WalletUnlockFailed,
#[fail(display = "could not open wallet! use `unlock` or `init`.")]
#[fail(display = "\x1b[31;1merror:\x1b[0m could not open wallet! use `unlock` or `init`.")]
NoWallet,
#[fail(display = "{} listener is closed! consider using `listen` first.", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m {} listener is closed! consider using `listen` first.", 0)]
ClosedListener(String),
#[fail(display = "listener for {} already started!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m listener for {} already started!", 0)]
AlreadyListening(String),
#[fail(display = "contact named `{}` already exists!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m contact named `{}` already exists!", 0)]
ContactAlreadyExists(String),
#[fail(display = "could not find contact named `{}`!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m could not find contact named `{}`!", 0)]
ContactNotFound(String),
#[fail(display = "invalid character!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m invalid character!")]
InvalidBase58Character(char, usize),
#[fail(display = "invalid length!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m invalid length!")]
InvalidBase58Length,
#[fail(display = "invalid checksum!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m invalid checksum!")]
InvalidBase58Checksum,
#[fail(display = "invalid network!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m invalid network!")]
InvalidBase58Version,
#[fail(display = "invalid key!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m invalid key!")]
InvalidBase58Key,
#[fail(display = "could not parse number from string!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m could not parse number from string!")]
NumberParsingError,
#[fail(display = "unknown address type `{}`!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m unknown address type `{}`!", 0)]
UnknownAddressType(String),
#[fail(display = "could not parse `{}` to a grinbox address!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m could not parse `{}` to a grinbox address!", 0)]
GrinboxAddressParsingError(String),
#[fail(display = "could not parse `{}` to a keybase address!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m could not parse `{}` to a keybase address!", 0)]
KeybaseAddressParsingError(String),
#[fail(display = "could not parse `{}` to a https address!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m could not parse `{}` to a https address!", 0)]
HttpsAddressParsingError(String),
#[fail(display = "could not send keybase message!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m could not send keybase message!")]
KeybaseMessageSendError,
#[fail(display = "failed receiving slate!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m failed receiving slate!")]
GrinWalletReceiveError,
#[fail(display = "failed verifying slate messages!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m failed verifying slate messages!")]
GrinWalletVerifySlateMessagesError,
#[fail(display = "failed finalizing slate!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m failed finalizing slate!")]
GrinWalletFinalizeError,
#[fail(display = "failed posting transaction!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m failed posting transaction!")]
GrinWalletPostError,
#[fail(display = "keybase not found! consider installing keybase locally first.")]
#[fail(display = "\x1b[31;1merror:\x1b[0m keybase not found! consider installing keybase locally first.")]
KeybaseNotFound,
#[fail(display = "grinbox websocket terminated unexpectedly!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m grinbox websocket terminated unexpectedly!")]
GrinboxWebsocketAbnormalTermination,
#[fail(display = "rejecting invoice as auto invoice acceptance is turned off!")]
#[fail(display = "\x1b[31;1merror:\x1b[0m rejecting invoice as auto invoice acceptance is turned off!")]
DoesNotAcceptInvoices,
#[fail(display = "rejecting invoice as amount '{}' is too big!", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m rejecting invoice as amount '{}' is too big!", 0)]
InvoiceAmountTooBig(u64),
#[fail(display = "please stop the listeners before doing this operation")]
#[fail(display = "\x1b[31;1merror:\x1b[0m please stop the listeners before doing this operation")]
HasListener,
#[fail(display = "wallet already unlocked")]
#[fail(display = "\x1b[31;1merror:\x1b[0m wallet already unlocked")]
WalletAlreadyUnlocked,
#[fail(display = "unable to encrypt message")]
#[fail(display = "\x1b[31;1merror:\x1b[0m unable to encrypt message")]
Encryption,
#[fail(display = "unable to decrypt message")]
#[fail(display = "\x1b[31;1merror:\x1b[0m unable to decrypt message")]
Decryption,
#[fail(display = "restore error")]
#[fail(display = "\x1b[31;1merror:\x1b[0m restore error")]
Restore,
#[fail(display = "unknown account: {}", 0)]
#[fail(display = "\x1b[31;1merror:\x1b[0m unknown account: {}", 0)]
UnknownAccountLabel(String),
#[fail(display = "http request error")]
#[fail(display = "\x1b[31;1merror:\x1b[0m http request error")]
HttpRequest
}
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ fn main() {
let mut grinbox_broker: Option<(GrinboxPublisher, GrinboxSubscriber)> = None;
let mut keybase_broker: Option<(KeybasePublisher, KeybaseSubscriber)> = None;


let account = matches.value_of("account").unwrap_or("default").to_string();
let has_wallet = if matches.is_present("passphrase") {
let passphrase = password_prompt(matches.value_of("passphrase"));
Expand Down Expand Up @@ -483,7 +482,7 @@ fn main() {
let result = do_command(&command, &mut config, wallet.clone(), address_book.clone(), &mut keybase_broker, &mut grinbox_broker, &mut out_is_safe);

if let Err(err) = result {
cli_message!("{}: {}", "ERROR".bright_red(), err);
cli_message!("{}", err);
}

if out_is_safe {
Expand Down

0 comments on commit 0e092a7

Please sign in to comment.