Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace failure crate with anyhow+thiserror #286

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 43 additions & 25 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion cincinnati/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ commons = { path = "../commons" }
custom_debug_derive = "^0.1.7"
daggy = { version = "^0.6.0", features = [ "serde-1" ] }
env_logger = "^0.6.0"
failure = "^0.1.1"
futures = "0.3"
futures-locks = "0.5.0"
lazy_static = "^1.2.0"
Expand Down
13 changes: 6 additions & 7 deletions cincinnati/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[macro_use]
extern crate failure;

#[macro_use]
extern crate serde_derive;

#[macro_use]
pub mod plugins;

use commons::prelude_errors::*;
use daggy::petgraph::visit::{IntoNodeReferences, NodeRef};
use daggy::{Dag, EdgeIndex, Walker};
use failure::{Error, Fallible};
use serde::de::{self, Deserialize, Deserializer, MapAccess, Visitor};
use serde::ser::{Serialize, SerializeStruct, Serializer};
use std::{collections, fmt};
Expand Down Expand Up @@ -154,25 +151,27 @@ pub struct Empty;

/// Errors that can be returned by the methods in this library
pub mod errors {
use commons::prelude_errors::*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not seen this before. Can you please explain purpose of this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also did not find any pointers in internet e.g. https://doc.rust-lang.org/std/prelude/index.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prelude is a naming convention for modules which export commonly used items. AFAIU there's nothing right or wrong about it, and I decided to include errors in the name as this prelude is about error related items only.


/// Edge already exists
#[derive(Debug, Fail, Eq, PartialEq)]
#[fail(display = "edge from {:?} to {:?} already exists", from, to)]
#[error("edge from {:?} to {:?} already exists", from, to)]
pub struct EdgeAlreadyExists {
pub(crate) from: String,
pub(crate) to: String,
}

/// Edge doesn't exist
#[derive(Debug, Fail, Eq, PartialEq)]
#[fail(display = "edge from '{:?}' to '{:?}' doesn't exist", from, to)]
#[error("edge from '{:?}' to '{:?}' doesn't exist", from, to)]
pub struct EdgeDoesntExist {
pub(crate) from: String,
pub(crate) to: String,
}

/// Missing node weight
#[derive(Debug, Fail, Eq, PartialEq)]
#[fail(display = "NodeWeight with index {} is missing", 0)]
#[error("NodeWeight with index {} is missing", 0)]
pub struct NodeWeightMissing(pub(crate) usize);
}

Expand Down
2 changes: 1 addition & 1 deletion cincinnati/src/plugins/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::internal::openshift_secondary_metadata_parser::{
use super::internal::release_scrape_dockerv2::{
ReleaseScrapeDockerv2Plugin, ReleaseScrapeDockerv2Settings,
};
use failure::{bail, format_err, Fallible};
use commons::prelude_errors::*;
use std::fmt::Debug;

/// Key used to look up plugin-type in a configuration entry.
Expand Down
2 changes: 1 addition & 1 deletion cincinnati/src/plugins/external/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ mod tests {
use async_trait::async_trait;
use cincinnati::plugins::{interface, ExternalIO, ExternalPlugin, InternalIO, PluginResult};
use cincinnati::testing::generate_graph;
use commons::prelude_errors::*;
use commons::testing::init_runtime;
use failure::Fallible;
use log::trace;
use std::convert::TryInto;

Expand Down
6 changes: 3 additions & 3 deletions cincinnati/src/plugins/internal/cincinnati_graph_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use self::cincinnati::plugins::prelude::*;
use self::cincinnati::plugins::prelude_plugin_impl::*;
use self::cincinnati::CONTENT_TYPE;

use commons::prelude_errors::*;
use commons::GraphError;
use failure::{Fallible, ResultExt};
use prometheus::Counter;
use reqwest;
use reqwest::header::{HeaderValue, ACCEPT};
Expand Down Expand Up @@ -158,8 +158,8 @@ mod tests {
use super::*;
use cincinnati::testing::generate_custom_graph;
use commons::metrics::{self, RegistryWrapper};
use commons::prelude_errors::*;
use commons::testing::{self, init_runtime};
use failure::{bail, Fallible};
use prometheus::Registry;

macro_rules! fetch_upstream_success_test {
Expand Down Expand Up @@ -318,7 +318,7 @@ mod tests {
let metrics_call = metrics::serve::<metrics::RegistryWrapper>(actix_web::web::Data::new(
RegistryWrapper(registry),
));
let resp = rt.block_on(metrics_call)?;
let resp = rt.block_on(metrics_call);

assert_eq!(resp.status(), 200);
if let actix_web::body::ResponseBody::Body(body) = resp.body() {
Expand Down
1 change: 0 additions & 1 deletion cincinnati/src/plugins/internal/edge_add_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ mod tests {
use cincinnati::testing::generate_custom_graph;
use cincinnati::MapImpl;
use commons::testing::init_runtime;
use failure::ResultExt;

static KEY_PREFIX: &str = "test_key";

Expand Down
Loading