Skip to content

Commit

Permalink
Move to anyhow instead of failure (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaishavGandhi committed May 2, 2020
1 parent 7470e05 commit 2bfa512
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 52 deletions.
42 changes: 7 additions & 35 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ comfy-table = "0.1.0"
console="0.10.0"
confy = "0.4.0"
dialoguer = "0.5.0"
failure = "0.1.7"
anyhow = "1.0.28"
futures= {version = "0.3.4", features = ["thread-pool"]}
tokio = "0.2.16"
10 changes: 4 additions & 6 deletions src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::structs::{FabConfig, WhoAmIResponse};
use crate::WHO_AM_I;
use failure::Error;
use anyhow::{anyhow, Error};
use reqwest::RequestBuilder;
use serde::Deserialize;
use std::fs::{read_to_string, File};
Expand Down Expand Up @@ -76,9 +76,7 @@ pub async fn send<T: serde::de::DeserializeOwned>(
}
}
}
Result::Err(failure::err_msg(
"Token regenerated. Please try the command again",
))
Err(anyhow!("Token regenerated. Please try the command again",))
}

/// Prompts for a token and writes the token to the configuration file.
Expand All @@ -92,7 +90,7 @@ fn prompt_token(hosted_instance: &str) -> Result<String, Error> {
api_token = api_token.trim().to_string();

if api_token.is_empty() {
return Result::Err(failure::err_msg("API Token cannot be null or empty"));
return Result::Err(anyhow!("API Token cannot be null or empty"));
}

Result::Ok(api_token)
Expand All @@ -113,7 +111,7 @@ fn prompt_hosted_instance() -> Result<String, Error> {

// Make sure hosted instance is present.
if hosted_instance.is_empty() {
return Result::Err(failure::err_msg("Hosted instance cannot be empty"));
return Result::Err(anyhow!("Hosted instance cannot be empty"));
}

Ok(hosted_instance)
Expand Down
4 changes: 2 additions & 2 deletions src/diffs.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::structs::{FabConfig, Revision, RevisionData};
use crate::NO_BORDER_PRESET;
use crate::{auth, users};
use anyhow::{anyhow, Error};
use clap::ArgMatches;
use comfy_table::{Attribute, Cell, CellAlignment, ContentArrangement, Table};
use failure::Error;
use serde_json::{Map, Value};
use tokio::runtime::Runtime;

Expand Down Expand Up @@ -36,7 +36,7 @@ pub async fn get_authored_diffs(config: &FabConfig) -> Result<Vec<Revision>, Err
/// Get diffs authored by given author
pub async fn get_diffs(config: &FabConfig, author: &Option<&str>) -> Result<Vec<Revision>, Error> {
if author.is_none() {
return Err(failure::err_msg("No author specified"));
return Err(anyhow!("No author specified"));
}

let author = author.unwrap();
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
extern crate serde_json;

use crate::preferences::Preferences;
use anyhow::{anyhow, Error};
use clap_generate::generate;
use clap_generate::generators::{Bash, Elvish, Fish, PowerShell, Zsh};
use failure::Error;
use std::io;
mod auth;
mod cli;
Expand Down Expand Up @@ -61,7 +61,7 @@ fn main() -> Result<(), Error> {
"fab",
&mut io::stdout(),
),
_ => return Err(failure::err_msg("No matching shell specified")),
_ => return Err(anyhow!("No matching shell specified")),
}
}
Ok(())
Expand All @@ -71,7 +71,7 @@ fn main() -> Result<(), Error> {
///
/// It's important to remember to add any default values otherwise confy will blow
/// up with a BadTomlError
fn migrate_preferences(preferences: Preferences) -> Result<Preferences, failure::Error> {
fn migrate_preferences(preferences: Preferences) -> Result<Preferences, Error> {
let preferences = Preferences {
default_limit_str: preferences.default_limit.to_string(),
default_limit: preferences.default_limit,
Expand Down
2 changes: 1 addition & 1 deletion src/preferences.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Error;
use clap::ArgMatches;
use console::style;
use dialoguer::theme::ColorfulTheme;
use dialoguer::{Checkboxes, Input, Select};
use failure::Error;
use serde::{Deserialize, Serialize};
use std::io;

Expand Down
2 changes: 1 addition & 1 deletion src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::diffs::{get_authored_diffs, get_needs_review_diffs, render_diffs};
use crate::preferences::Preferences;
use crate::structs::FabConfig;
use crate::tasks::{get_tasks, render_tasks, Priority};
use anyhow::Error;
use clap::ArgMatches;
use console::style;
use failure::Error;
use futures::future::join3;

pub fn process_summary(
Expand Down
4 changes: 2 additions & 2 deletions src/tasks.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::preferences::Preferences;
use crate::structs::FabConfig;
use crate::{auth, NO_BORDER_PRESET};
use anyhow::{anyhow, Error};
use clap::ArgMatches;
use comfy_table::{Attribute, Cell, CellAlignment, Color, ContentArrangement, Table};
use failure::Error;
use serde::Deserialize;
use serde_json::{Map, Value};

Expand Down Expand Up @@ -183,7 +183,7 @@ impl Priority {
"normal" => Result::Ok(50),
"low" => Result::Ok(25),
"wishlist" => Result::Ok(0),
_ => Result::Err(failure::err_msg("Unknown value of priority")),
_ => Result::Err(anyhow!("Unknown value of priority")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/users.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::auth;
use crate::structs::FabConfig;
use failure::Error;
use anyhow::Error;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};

Expand Down

0 comments on commit 2bfa512

Please sign in to comment.