Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Refactor code with 'bail!'
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi3700 committed Feb 8, 2024
1 parent 96e408b commit 3caa3c7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
6 changes: 2 additions & 4 deletions pulsar/src/commands/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions pulsar/src/commands/init.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -137,7 +137,7 @@ fn generate_or_get_reward_address(reward_address_exist: bool) -> Result<PublicKe
)?;

if !wants_new_key {
return Err(eyre!("New key creation was not confirmed"));
bail!("New key creation was not confirmed")
}

// generate new mnemonic and key pair
Expand Down
4 changes: 1 addition & 3 deletions pulsar/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ pub(crate) fn directory_parser(location: &str) -> Result<PathBuf> {

/// utilize `ByteSize` crate for the validation
pub(crate) fn size_parser(size: &str) -> Result<ByteSize> {
let Ok(size) = size.parse::<ByteSize>() else {
return Err(eyre!("could not parse the value!"));
};
let Ok(size) = size.parse::<ByteSize>() 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 {
Expand Down

0 comments on commit 3caa3c7

Please sign in to comment.