From 820a3cfd282251490bd4d559e8b6d21387d8d800 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 29 Sep 2020 00:28:58 +0100 Subject: [PATCH] remove failure --- Cargo.lock | 109 +++------------------------------ Cargo.toml | 3 +- src/engine/fut/analyze.rs | 2 +- src/engine/fut/crawl.rs | 2 +- src/engine/machines/crawler.rs | 2 +- src/engine/mod.rs | 4 +- src/interactors/bitbucket.rs | 2 +- src/interactors/crates.rs | 6 +- src/interactors/github.rs | 4 +- src/interactors/gitlab.rs | 2 +- src/interactors/mod.rs | 4 +- src/interactors/rustsec.rs | 4 +- src/main.rs | 4 +- src/models/crates.rs | 4 +- src/models/repo.rs | 4 +- src/parsers/manifest.rs | 6 +- src/utils/cache.rs | 15 +++-- 17 files changed, 39 insertions(+), 138 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ea3768..d962494 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,47 +6,24 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2692800d602527d2b8fea50036119c37df74ab565b10e285706a3dcec0ec3e16" -[[package]] -name = "addr2line" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" - [[package]] name = "antidote" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34fde25430d87a9388dadbe6e34d7f72a462c8b43ac8d309b42b0a8505d7e2a5" +[[package]] +name = "anyhow" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" + [[package]] name = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "backtrace" -version = "0.3.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293" -dependencies = [ - "addr2line", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "badge" version = "0.2.0" @@ -269,28 +246,6 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" -[[package]] -name = "failure" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" -dependencies = [ - "backtrace", - "failure_derive", -] - -[[package]] -name = "failure_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] - [[package]] name = "fake-simd" version = "0.1.2" @@ -365,12 +320,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "gimli" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" - [[package]] name = "hashbrown" version = "0.9.1" @@ -652,16 +601,6 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "miniz_oxide" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c60c0dfe32c10b43a144bad8fc83538c52f58302c92300ea7ec7bf7b38d5a7b9" -dependencies = [ - "adler", - "autocfg", -] - [[package]] name = "mio" version = "0.6.22" @@ -768,12 +707,6 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" - [[package]] name = "once_cell" version = "1.4.1" @@ -1021,12 +954,6 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea509065eb0b3c446acdd0102f0d46567dc30902dc0be91d6552035d92b0f4f8" -[[package]] -name = "rustc-demangle" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" - [[package]] name = "rustc_version" version = "0.2.3" @@ -1243,23 +1170,14 @@ dependencies = [ "opaque-debug", ] -[[package]] -name = "shared_failure" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95950ce835eb54ad4d85f5f597a3d7f78cb0f6622f65dabc2dac915d9edc404a" -dependencies = [ - "failure", -] - [[package]] name = "shiny-robots" version = "0.1.0" dependencies = [ + "anyhow", "badge", "cadence", "derive_more", - "failure", "futures", "hyper 0.11.27", "hyper-tls", @@ -1274,7 +1192,6 @@ dependencies = [ "semver 0.11.0", "serde 1.0.116", "serde_json 1.0.57", - "shared_failure", "slog", "slog-json", "tokio-core", @@ -1339,18 +1256,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "synstructure" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", -] - [[package]] name = "take" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 38b140c..48377cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,9 @@ members = [ [dependencies] badge = { path = "./libs/badge" } +anyhow = "1" cadence = "0.13" derive_more = "0.99" -failure = "0.1" futures = "0.1" hyper = "0.11" hyper-tls = "0.1" @@ -29,7 +29,6 @@ rustsec = "0.6.0" semver = { version = "0.11", features = ["serde"] } serde = { version = "1", features = ["derive"] } serde_json = "1" -shared_failure = "0.1" slog = "2" slog-json = "2" tokio-core = "0.1" diff --git a/src/engine/fut/analyze.rs b/src/engine/fut/analyze.rs index 43aed2b..f2d3a81 100644 --- a/src/engine/fut/analyze.rs +++ b/src/engine/fut/analyze.rs @@ -1,4 +1,4 @@ -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use futures::stream::futures_unordered; use futures::{Future, Poll, Stream}; diff --git a/src/engine/fut/crawl.rs b/src/engine/fut/crawl.rs index 179ffcb..827a39e 100644 --- a/src/engine/fut/crawl.rs +++ b/src/engine/fut/crawl.rs @@ -1,6 +1,6 @@ use std::mem; -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use futures::stream::FuturesOrdered; use futures::{try_ready, Async, Future, Poll, Stream}; use relative_path::RelativePathBuf; diff --git a/src/engine/machines/crawler.rs b/src/engine/machines/crawler.rs index 3fc3768..0936ca5 100644 --- a/src/engine/machines/crawler.rs +++ b/src/engine/machines/crawler.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use indexmap::IndexMap; use relative_path::RelativePathBuf; diff --git a/src/engine/mod.rs b/src/engine/mod.rs index 30ff191..8f6efeb 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -4,7 +4,7 @@ use std::time::{Duration, Instant}; use cadence::prelude::*; use cadence::{MetricSink, NopMetricSink, StatsdClient}; -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use futures::future::join_all; use futures::{future, Future}; use hyper::client::HttpConnector; @@ -176,7 +176,7 @@ impl Engine { .iter() .find(|release| release.version == crate_path.version) { - None => future::Either::A(future::err(format_err!( + None => future::Either::A(future::err(anyhow!( "could not find crate release with version {}", crate_path.version ))), diff --git a/src/interactors/bitbucket.rs b/src/interactors/bitbucket.rs index d695949..8239c05 100644 --- a/src/interactors/bitbucket.rs +++ b/src/interactors/bitbucket.rs @@ -1,4 +1,4 @@ -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use hyper::Uri; use relative_path::RelativePathBuf; diff --git a/src/interactors/crates.rs b/src/interactors/crates.rs index 5234425..a25cc49 100644 --- a/src/interactors/crates.rs +++ b/src/interactors/crates.rs @@ -1,6 +1,6 @@ use std::str; -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use futures::{future, Future, IntoFuture, Stream}; use hyper::{Error as HyperError, Method, Request, Response, Uri}; use semver::{Version, VersionReq}; @@ -100,7 +100,7 @@ where Box::new(self.0.call(request).from_err().and_then(move |response| { let status = response.status(); if !status.is_success() { - try_future!(Err(format_err!("Status code {} for URI {}", status, uri))); + try_future!(Err(anyhow!("Status code {} for URI {}", status, uri))); } let body_future = response.body().concat2().from_err(); @@ -174,7 +174,7 @@ where service.call(request).from_err().and_then(move |response| { let status = response.status(); if !status.is_success() { - future::Either::A(future::err(format_err!( + future::Either::A(future::err(anyhow!( "Status code {} for URI {}", status, uri diff --git a/src/interactors/github.rs b/src/interactors/github.rs index 3725046..e1e455a 100644 --- a/src/interactors/github.rs +++ b/src/interactors/github.rs @@ -1,4 +1,4 @@ -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use futures::{Future, Stream}; use hyper::header::UserAgent; use hyper::{Error as HyperError, Method, Request, Response, Uri}; @@ -66,7 +66,7 @@ where Box::new(self.0.call(request).from_err().and_then(|response| { let status = response.status(); if !status.is_success() { - try_future!(Err(format_err!( + try_future!(Err(anyhow!( "Status code {} for popular repo search", status ))); diff --git a/src/interactors/gitlab.rs b/src/interactors/gitlab.rs index 11514b7..2ea5a66 100644 --- a/src/interactors/gitlab.rs +++ b/src/interactors/gitlab.rs @@ -1,4 +1,4 @@ -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use hyper::Uri; use relative_path::RelativePathBuf; diff --git a/src/interactors/mod.rs b/src/interactors/mod.rs index dc8b421..46b4d85 100644 --- a/src/interactors/mod.rs +++ b/src/interactors/mod.rs @@ -1,4 +1,4 @@ -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use futures::{Future, Stream}; use hyper::{Error as HyperError, Method, Request, Response}; use relative_path::RelativePathBuf; @@ -38,7 +38,7 @@ where Box::new(self.0.call(request).from_err().and_then(move |response| { let status = response.status(); if !status.is_success() { - try_future!(Err(format_err!("Status code {} for URI {}", status, uri))); + try_future!(Err(anyhow!("Status code {} for URI {}", status, uri))); } let body_future = response.body().concat2().from_err(); diff --git a/src/interactors/rustsec.rs b/src/interactors/rustsec.rs index 93f5c2f..caf74f2 100644 --- a/src/interactors/rustsec.rs +++ b/src/interactors/rustsec.rs @@ -1,7 +1,7 @@ use std::str; use std::sync::Arc; -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use futures::{future, Future, IntoFuture, Stream}; use hyper::{Error as HyperError, Method, Request, Response}; use rustsec::db::AdvisoryDatabase; @@ -32,7 +32,7 @@ where service.call(request).from_err().and_then(|response| { let status = response.status(); if !status.is_success() { - future::Either::A(future::err(format_err!( + future::Either::A(future::err(anyhow!( "Status code {} when fetching advisory db", status ))) diff --git a/src/main.rs b/src/main.rs index 29959be..0ea87b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ #![deny(rust_2018_idioms)] +#![allow(unused)] + -#[macro_use] -extern crate failure; #[macro_use] extern crate try_future; diff --git a/src/models/crates.rs b/src/models/crates.rs index 9d7d294..28324cc 100644 --- a/src/models/crates.rs +++ b/src/models/crates.rs @@ -1,7 +1,7 @@ use std::borrow::Borrow; use std::str::FromStr; -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use indexmap::IndexMap; use relative_path::RelativePathBuf; use semver::{Version, VersionReq}; @@ -51,7 +51,7 @@ impl FromStr for CrateName { .all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-'); if !is_valid { - Err(format_err!("failed to validate crate name: {}", input)) + Err(anyhow!("failed to validate crate name: {}", input)) } else { Ok(CrateName(input.to_string())) } diff --git a/src/models/repo.rs b/src/models/repo.rs index 885c190..6b0adc8 100644 --- a/src/models/repo.rs +++ b/src/models/repo.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use failure::Error; +use anyhow::{anyhow, ensure, Error}; #[derive(Clone, Debug)] pub struct Repository { @@ -50,7 +50,7 @@ impl FromStr for RepoSite { "github" => Ok(RepoSite::Github), "gitlab" => Ok(RepoSite::Gitlab), "bitbucket" => Ok(RepoSite::Bitbucket), - _ => Err(format_err!("unknown repo site identifier")), + _ => Err(anyhow!("unknown repo site identifier")), } } } diff --git a/src/parsers/manifest.rs b/src/parsers/manifest.rs index 19f900c..b88c05f 100644 --- a/src/parsers/manifest.rs +++ b/src/parsers/manifest.rs @@ -1,4 +1,4 @@ -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use indexmap::IndexMap; use relative_path::RelativePathBuf; use semver::VersionReq; @@ -132,9 +132,7 @@ pub fn parse_manifest_toml(input: &str) -> Result { deps, members, }), - (None, None) => Err(format_err!( - "neither workspace nor package found in manifest" - )), + (None, None) => Err(anyhow!("neither workspace nor package found in manifest")), } } diff --git a/src/utils/cache.rs b/src/utils/cache.rs index a96663c..5018b42 100644 --- a/src/utils/cache.rs +++ b/src/utils/cache.rs @@ -4,11 +4,10 @@ use std::ops::Deref; use std::sync::Mutex; use std::time::{Duration, Instant}; -use failure::Error; +use anyhow::{anyhow, ensure, Error}; use futures::future::{FromErr, Shared, SharedItem}; use futures::{Future, Poll}; use lru_cache::LruCache; -use shared_failure::SharedFailure; use tokio_service::Service; pub struct Cache @@ -18,7 +17,7 @@ where { inner: S, duration: Duration, - cache: Mutex>)>>, + cache: Mutex>)>>, } impl Debug for Cache @@ -55,7 +54,7 @@ where { type Request = S::Request; type Response = CachedItem; - type Error = SharedFailure; + type Error = Error; type Future = Cached; fn call(&self, req: Self::Request) -> Self::Future { @@ -74,7 +73,7 @@ where } } -pub struct Cached>(Shared>); +pub struct Cached>(Shared>); impl Debug for Cached where @@ -88,13 +87,13 @@ where impl> Future for Cached { type Item = CachedItem; - type Error = SharedFailure; + type Error = Error; fn poll(&mut self) -> Poll { self.0 .poll() - .map_err(|err| (*err).clone()) - .map(|_async| _async.map(CachedItem)) + .map_err(|_err| anyhow!("TODO: shared error not clone-able")) + .map(|item| item.map(CachedItem)) } }