Skip to content

Commit

Permalink
[refactor]: chores
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Balashov <43530070+0x009922@users.noreply.github.com>
  • Loading branch information
0x009922 committed Apr 17, 2024
1 parent 786b8c6 commit ecd3119
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ fn genesis_domain(public_key: PublicKey) -> Domain {
pub enum ConfigError {
#[error("Error occurred while reading configuration from file(s) and environment")]
ReadConfig,
#[error("Error occurred while validating configuration integrity")]
ParseConfig,
#[error("Error occurred while reading genesis block")]
ReadGenesis,
#[error("The network consists from this one peer only")]
Expand All @@ -596,7 +598,7 @@ pub enum ConfigError {
SameNetworkAndToriiAddrs,
#[error("Invalid directory path found")]
InvalidDirPath,
#[error("Cannot bind a listener to address `{addr}`")]
#[error("Network error: cannot listen to address `{addr}`")]
CannotBindAddress { addr: SocketAddr },
}

Expand All @@ -623,7 +625,7 @@ pub fn read_config_and_genesis(
.read_and_complete::<UserConfig>()
.change_context(ConfigError::ReadConfig)?
.parse()
.change_context(ConfigError::ReadConfig)?;
.change_context(ConfigError::ParseConfig)?;

let genesis = if let Genesis::Full { key_pair, file } = &config.genesis {
let raw_block = RawGenesisBlock::from_path(file.resolve_relative_path())
Expand Down
1 change: 1 addition & 0 deletions client_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ json5 = { workspace = true }
once_cell = { workspace = true }
serde_json = { workspace = true }
erased-serde = "0.3.31"
supports-color = { workspace = true }

[build-dependencies]
vergen = { version = "8.2.5", default-features = false }
Expand Down
14 changes: 13 additions & 1 deletion client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use erased_serde::Serialize;
use error_stack::{IntoReportCompat, ResultExt};
use error_stack::{fmt::ColorMode, IntoReportCompat, ResultExt};
use eyre::{eyre, Error, Result, WrapErr};
use iroha_client::{
client::{Client, QueryResult},
Expand Down Expand Up @@ -192,6 +192,8 @@ fn main() -> error_stack::Result<(), MainError> {
verbose,
} = clap::Parser::parse();

error_stack::Report::set_color_mode(color_mode());

let config = Config::load(config_path)
// FIXME: would be nice to NOT change the context, it's unnecessary
.change_context(MainError::Config)
Expand All @@ -217,6 +219,16 @@ fn main() -> error_stack::Result<(), MainError> {
Ok(())
}

fn color_mode() -> ColorMode {
if supports_color::on(supports_color::Stream::Stdout)
&& supports_color::on(supports_color::Stream::Stderr)
{
ColorMode::Color
} else {
ColorMode::None
}
}

/// Submit instruction with metadata to network.
///
/// # Errors
Expand Down
4 changes: 2 additions & 2 deletions config/base/src/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ pub struct TomlSource {

#[derive(Error, Debug, Copy, Clone)]
pub enum FromFileError {
#[error("Failed to read file from disk")]
#[error("File system error")]
Read,
#[error("Failed to parse file contents as TOML")]
#[error("Error while deserializing file contents as TOML")]
Parse,
}

Expand Down
1 change: 1 addition & 0 deletions primitives/src/unique_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl<T> UniqueVec<T> {
}

/// A result for [`UniqueVec::push`]
#[derive(Debug)]
pub enum PushResult<T> {
/// The element was pushed into the vec
Ok,
Expand Down

0 comments on commit ecd3119

Please sign in to comment.