From 3caa3c7473e433891b16f0a4695e27ba095d32bb Mon Sep 17 00:00:00 2001 From: abhi3700 Date: Thu, 8 Feb 2024 18:35:34 +0530 Subject: [PATCH] Refactor code with 'bail!' --- pulsar/src/commands/farm.rs | 6 ++---- pulsar/src/commands/init.rs | 4 ++-- pulsar/src/utils.rs | 4 +--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pulsar/src/commands/farm.rs b/pulsar/src/commands/farm.rs index 16e77d79..bb6354e3 100644 --- a/pulsar/src/commands/farm.rs +++ b/pulsar/src/commands/farm.rs @@ -2,7 +2,7 @@ use std::io::Write; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -use color_eyre::eyre::{eyre, Context, Error, Result}; +use color_eyre::eyre::{bail, eyre, Context, Error, Result}; use color_eyre::Report; use futures::prelude::*; use indicatif::{ProgressBar, ProgressStyle}; @@ -42,9 +42,7 @@ pub(crate) async fn farm(is_verbose: bool, enable_domains: bool, no_rotation: bo let instance = SingleInstance::new(SINGLE_INSTANCE) .context("Cannot take the instance lock from the OS! Aborting...")?; if !instance.is_single() { - return Err(eyre!( - "It seems like there is already a farming instance running. Aborting...", - )); + bail!("It seems like there is already a farming instance running. Aborting...",) } // raise file limit raise_fd_limit(); diff --git a/pulsar/src/commands/init.rs b/pulsar/src/commands/init.rs index 3004a226..704835c9 100644 --- a/pulsar/src/commands/init.rs +++ b/pulsar/src/commands/init.rs @@ -1,7 +1,7 @@ use std::io::{BufRead, Write}; use std::str::FromStr; -use color_eyre::eyre::{eyre, Context, Error, Result}; +use color_eyre::eyre::{bail, Context, Error, Result}; use crossterm::terminal::{Clear, ClearType}; use crossterm::{cursor, execute}; use rand::prelude::IteratorRandom; @@ -137,7 +137,7 @@ fn generate_or_get_reward_address(reward_address_exist: bool) -> Result Result { /// utilize `ByteSize` crate for the validation pub(crate) fn size_parser(size: &str) -> Result { - let Ok(size) = size.parse::() else { - return Err(eyre!("could not parse the value!")); - }; + let Ok(size) = size.parse::() else { bail!("could not parse the value!") }; if size < MIN_FARM_SIZE { Err(eyre!(format!("farm size cannot be smaller than {}", MIN_FARM_SIZE))) } else {