From 73362c6de304659e70085bef25277810a2c0e411 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 30 Oct 2018 18:40:53 +0100 Subject: [PATCH] imag-link: Move from error-chain to failure Signed-off-by: Matthias Beyer --- bin/core/imag-link/Cargo.toml | 3 ++- bin/core/imag-link/src/main.rs | 41 ++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/bin/core/imag-link/Cargo.toml b/bin/core/imag-link/Cargo.toml index dd503bef..20db392c 100644 --- a/bin/core/imag-link/Cargo.toml +++ b/bin/core/imag-link/Cargo.toml @@ -25,8 +25,9 @@ maintenance = { status = "actively-developed" } log = "0.4.0" url = "1.5" toml = "0.4" -toml-query = "0.7" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "failure" } prettytable-rs = "0.8" +failure = "0.1" libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs index 5a177308..e0b55149 100644 --- a/bin/core/imag-link/src/main.rs +++ b/bin/core/imag-link/src/main.rs @@ -35,6 +35,7 @@ #[macro_use] extern crate log; extern crate clap; extern crate url; +extern crate failure; #[macro_use] extern crate prettytable; #[cfg(test)] extern crate toml; #[cfg(test)] extern crate toml_query; @@ -55,22 +56,24 @@ extern crate libimagutil; use std::io::Write; use std::path::PathBuf; +use failure::Error; +use failure::err_msg; + use libimagentrylink::external::ExternalLinker; use libimagentrylink::internal::InternalLinker; use libimagentrylink::internal::store_check::StoreLinkConsistentExt; -use libimagentrylink::error::LinkError as LE; use libimagerror::trace::{MapErrTrace, trace_error}; use libimagerror::exit::ExitUnwrap; use libimagerror::io::ToExitCode; use libimagrt::runtime::Runtime; use libimagrt::setup::generate_runtime_setup; -use libimagstore::error::StoreError; use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreId; use libimagutil::warn_exit::warn_exit; use libimagutil::warn_result::*; use url::Url; +use failure::Fallible as Result; mod ui; @@ -80,7 +83,7 @@ fn main() { let version = make_imag_version!(); let rt = generate_runtime_setup("imag-link", &version, - "Add/Remove links between entries", + "Link entries", build_ui); if rt.cli().is_present("check-consistency") { let exit_code = match rt.store().check_link_consistency() { @@ -119,11 +122,11 @@ fn main() { warn_exit("No commandline call", 1) } }) - .ok_or(LE::from("No commandline call".to_owned())) + .ok_or_else(|| Error::from(err_msg("No commandline call".to_owned()))) .map_err_trace_exit_unwrap(1); } -fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result>, StoreError> { +fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result>> { use libimagstore::storeid::StoreId; debug!("Getting: {:?}", name); @@ -336,11 +339,12 @@ mod tests { use toml::value::Value; use toml_query::read::TomlValueReadExt; - use toml_query::error::Result as TomlQueryResult; + use failure::Fallible as Result; + use failure::Error; use libimagrt::runtime::Runtime; use libimagstore::storeid::StoreId; - use libimagstore::store::{Result as StoreResult, FileLockEntry, Entry}; + use libimagstore::store::{FileLockEntry, Entry}; fn setup_logging() { let _ = ::env_logger::try_init(); @@ -355,7 +359,7 @@ mod tests { use self::mock::generate_test_runtime; use self::mock::reset_test_runtime; - fn create_test_default_entry<'a, S: AsRef>(rt: &'a Runtime, name: S) -> StoreResult { + fn create_test_default_entry<'a, S: AsRef>(rt: &'a Runtime, name: S) -> Result { let mut path = PathBuf::new(); path.set_file_name(name); @@ -376,11 +380,10 @@ mod tests { Ok(id) } - fn get_entry_links<'a>(entry: &'a FileLockEntry<'a>) -> TomlQueryResult<&'a Value> { - match entry.get_header().read(&"links.internal".to_owned()) { - Err(e) => Err(e), - Ok(Some(v)) => Ok(v), - Ok(None) => panic!("Didn't find 'links' in {:?}", entry), + fn get_entry_links<'a>(entry: &'a FileLockEntry<'a>) -> Result<&'a Value> { + match entry.get_header().read(&"links.internal".to_owned()).map_err(Error::from)? { + Some(v) => Ok(v), + None => panic!("Didn't find 'links' in {:?}", entry), } } @@ -394,7 +397,7 @@ mod tests { #[test] fn test_link_modificates() { setup_logging(); - let rt = generate_test_runtime(vec!["test1", "test2"]) + let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) .unwrap(); debug!("Runtime created"); @@ -423,7 +426,7 @@ mod tests { #[test] fn test_linking_links() { setup_logging(); - let rt = generate_test_runtime(vec!["test1", "test2"]) + let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) .unwrap(); debug!("Runtime created"); @@ -452,7 +455,7 @@ mod tests { #[test] fn test_multilinking() { setup_logging(); - let rt = generate_test_runtime(vec!["test1", "test2"]) + let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) .unwrap(); debug!("Runtime created"); @@ -482,7 +485,7 @@ mod tests { #[test] fn test_linking_more_than_two() { setup_logging(); - let rt = generate_test_runtime(vec!["test1", "test2", "test3"]) + let rt = generate_test_runtime(vec!["internal", "test1", "test2", "test3"]) .unwrap(); debug!("Runtime created"); @@ -519,7 +522,7 @@ mod tests { #[test] fn test_linking_links_unlinking_removes_links() { setup_logging(); - let rt = generate_test_runtime(vec!["test1", "test2"]) + let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) .unwrap(); debug!("Runtime created"); @@ -555,7 +558,7 @@ mod tests { #[test] fn test_linking_and_unlinking_more_than_two() { setup_logging(); - let rt = generate_test_runtime(vec!["test1", "test2", "test3"]) + let rt = generate_test_runtime(vec!["internal", "test1", "test2", "test3"]) .unwrap(); debug!("Runtime created");