From 061967f268994fd467850b82ccf5f008d38e12f9 Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Mon, 4 Jun 2018 16:10:21 -0400 Subject: [PATCH] Convert query-pull/ to failure. --- query-pull/Cargo.toml | 3 ++- query-pull/src/errors.rs | 29 ++++++++++++----------------- query-pull/src/lib.rs | 10 ++++++---- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/query-pull/Cargo.toml b/query-pull/Cargo.toml index cc5e8b68..fe7b44c7 100644 --- a/query-pull/Cargo.toml +++ b/query-pull/Cargo.toml @@ -4,7 +4,8 @@ version = "0.0.1" workspace = ".." [dependencies] -error-chain = { git = "https://github.com/rnewman/error-chain", branch = "rnewman/sync" } +failure = "0.1.1" +failure_derive = "0.1.1" [dependencies.rusqlite] version = "0.13" diff --git a/query-pull/src/errors.rs b/query-pull/src/errors.rs index 94c38426..628a1170 100644 --- a/query-pull/src/errors.rs +++ b/query-pull/src/errors.rs @@ -8,28 +8,23 @@ // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. +use std; // To refer to std::result::Result. + use mentat_core::{ Entid, }; -error_chain! { - types { - Error, ErrorKind, ResultExt, Result; - } +use failure::{ + Error, +}; - errors { - UnnamedAttribute(id: Entid) { - description("unnamed attribute") - display("attribute {:?} has no name", id) - } +pub type Result = std::result::Result; - RepeatedDbId { - description(":db/id repeated") - display(":db/id repeated") - } - } +#[derive(Debug, Fail)] +pub enum PullError { + #[fail(display = "attribute {:?} has no name", _0)] + UnnamedAttribute(Entid), - links { - DbError(::mentat_db::Error, ::mentat_db::ErrorKind); - } + #[fail(display = ":db/id repeated")] + RepeatedDbId, } diff --git a/query-pull/src/lib.rs b/query-pull/src/lib.rs index 1b2d7804..22b48de6 100644 --- a/query-pull/src/lib.rs +++ b/query-pull/src/lib.rs @@ -57,8 +57,10 @@ /// [*])) ///! ``` +extern crate failure; + #[macro_use] -extern crate error_chain; +extern crate failure_derive; extern crate rusqlite; @@ -101,7 +103,7 @@ use mentat_query::{ pub mod errors; use errors::{ - ErrorKind, + PullError, Result, }; @@ -163,7 +165,7 @@ impl Puller { // In the unlikely event that we have an attribute with no name, we bail. schema.get_ident(*i) .map(|ident| ValueRc::new(ident.clone())) - .ok_or_else(|| ErrorKind::UnnamedAttribute(*i)) + .ok_or_else(|| PullError::UnnamedAttribute(*i)) }; let mut names: BTreeMap> = Default::default(); @@ -192,7 +194,7 @@ impl Puller { &PullConcreteAttribute::Ident(ref i) if i.as_ref() == db_id.as_ref() => { // We only allow :db/id once. if db_id_alias.is_some() { - bail!(ErrorKind::RepeatedDbId); + Err(PullError::RepeatedDbId)? } db_id_alias = Some(alias.unwrap_or_else(|| db_id.to_value_rc())); },