From 72242cf152dfedd65e99af05d66ae8abd2fa6532 Mon Sep 17 00:00:00 2001 From: Adi Seredinschi Date: Tue, 26 Jan 2021 18:46:31 +0100 Subject: [PATCH] Include cause in Failed errors (#555). Double-checking 'required' tag. --- relayer-cli/src/commands/query/channel.rs | 6 +++--- relayer-cli/src/commands/query/client.rs | 4 ++-- relayer-cli/src/commands/tx/transfer.rs | 9 +++++---- relayer-cli/src/conclude.rs | 12 ++++++++++++ relayer/src/channel.rs | 2 +- relayer/src/connection.rs | 4 ++-- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/relayer-cli/src/commands/query/channel.rs b/relayer-cli/src/commands/query/channel.rs index 31db1dfe84..b53b574e03 100644 --- a/relayer-cli/src/commands/query/channel.rs +++ b/relayer-cli/src/commands/query/channel.rs @@ -18,13 +18,13 @@ use crate::prelude::*; #[derive(Clone, Command, Debug, Options)] pub struct QueryChannelEndCmd { - #[options(free, help = "identifier of the chain to query")] + #[options(free, required, help = "identifier of the chain to query")] chain_id: Option, - #[options(free, help = "identifier of the port to query")] + #[options(free, required, help = "identifier of the port to query")] port_id: Option, - #[options(free, help = "identifier of the channel to query")] + #[options(free, required, help = "identifier of the channel to query")] channel_id: Option, #[options(help = "height of the state to query", short = "h")] diff --git a/relayer-cli/src/commands/query/client.rs b/relayer-cli/src/commands/query/client.rs index 168b260bab..151fefcb5c 100644 --- a/relayer-cli/src/commands/query/client.rs +++ b/relayer-cli/src/commands/query/client.rs @@ -22,10 +22,10 @@ use crate::prelude::*; /// Query client state command #[derive(Clone, Command, Debug, Options)] pub struct QueryClientStateCmd { - #[options(free, help = "identifier of the chain to query")] + #[options(free, required, help = "identifier of the chain to query")] chain_id: Option, - #[options(free, help = "identifier of the client to query")] + #[options(free, required, help = "identifier of the client to query")] client_id: Option, #[options(help = "the chain height which this query should reflect", short = "h")] diff --git a/relayer-cli/src/commands/tx/transfer.rs b/relayer-cli/src/commands/tx/transfer.rs index 1adea1cd0d..1b41224be9 100644 --- a/relayer-cli/src/commands/tx/transfer.rs +++ b/relayer-cli/src/commands/tx/transfer.rs @@ -17,20 +17,21 @@ use crate::prelude::*; #[derive(Clone, Command, Debug, Options)] pub struct TxRawSendPacketCmd { - #[options(free, help = "identifier of the source chain")] + #[options(free, required, help = "identifier of the source chain")] src_chain_id: ChainId, - #[options(free, help = "identifier of the destination chain")] + #[options(free, required, help = "identifier of the destination chain")] dest_chain_id: ChainId, - #[options(free, help = "identifier of the source port")] + #[options(free, required, help = "identifier of the source port")] src_port_id: PortId, - #[options(free, help = "identifier of the source channel")] + #[options(free, required, help = "identifier of the source channel")] src_channel_id: ChannelId, #[options( free, + required, help = "amount of coins (samoleans, by default) to send (e.g. `100000`)" )] amount: u64, diff --git a/relayer-cli/src/conclude.rs b/relayer-cli/src/conclude.rs index 900fa79ddb..3299741f8a 100644 --- a/relayer-cli/src/conclude.rs +++ b/relayer-cli/src/conclude.rs @@ -26,6 +26,18 @@ //! Output::error(format!("{}", e)).exit(); //! ``` //! +//! #### Note: +//! The resulting output that this approach generates is determined by the 'error' annotation given +//! to the error object `Kind::Query`. If this error object comprises any positional arguments, +//! e.g. as achieved by `Query(String, String)`, then it is important to cover these arguments +//! in the `error` annotation, for instance: +//! ```compile_fail +//! #[derive(Debug, Error)] +//! pub enum Kind { +//! #[error("failed with underlying causes: {0}, {1}")] +//! Query(String, String), // ... +//! ``` +//! //! - Exit from a query/tx with success: //! //! ```compile_fail diff --git a/relayer/src/channel.rs b/relayer/src/channel.rs index 793803521a..505c2d135c 100644 --- a/relayer/src/channel.rs +++ b/relayer/src/channel.rs @@ -25,7 +25,7 @@ use crate::relay::MAX_ITER; #[derive(Debug, Error)] pub enum ChannelError { - #[error("failed")] + #[error("failed with underlying cause: {0}")] Failed(String), #[error("failed during an operation on client ({0}) hosted by chain ({1}) with error: {2}")] diff --git a/relayer/src/connection.rs b/relayer/src/connection.rs index 74acb2a830..a65ef74b65 100644 --- a/relayer/src/connection.rs +++ b/relayer/src/connection.rs @@ -25,10 +25,10 @@ use crate::relay::MAX_ITER; #[derive(Debug, Error)] pub enum ConnectionError { - #[error("Failed")] + #[error("failed with underlying cause: {0}")] Failed(String), - #[error("constructor parameters do not match")] + #[error("constructor parameters do not match: underlying error: {0}")] ConstructorFailed(String), #[error("failed during a query to chain id {0} due to underlying error: {1}")]