summaryrefslogtreecommitdiffstats
path: root/lib/core
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core')
-rw-r--r--lib/core/libimagerror/Cargo.toml9
-rw-r--r--lib/core/libimagerror/src/errors.rs72
-rw-r--r--lib/core/libimagerror/src/lib.rs5
-rw-r--r--lib/core/libimagerror/src/trace.rs54
-rw-r--r--lib/core/libimagrt/Cargo.toml7
-rw-r--r--lib/core/libimagrt/src/application.rs8
-rw-r--r--lib/core/libimagrt/src/configuration.rs19
-rw-r--r--lib/core/libimagrt/src/iter.rs4
-rw-r--r--lib/core/libimagrt/src/lib.rs2
-rw-r--r--lib/core/libimagrt/src/logger.rs49
-rw-r--r--lib/core/libimagrt/src/runtime.rs38
-rw-r--r--lib/core/libimagstore/Cargo.toml4
-rw-r--r--lib/core/libimagstore/src/configuration.rs13
-rw-r--r--lib/core/libimagstore/src/file_abstraction/fs.rs45
-rw-r--r--lib/core/libimagstore/src/file_abstraction/inmemory.rs10
-rw-r--r--lib/core/libimagstore/src/file_abstraction/iter.rs2
-rw-r--r--lib/core/libimagstore/src/file_abstraction/mod.rs2
-rw-r--r--lib/core/libimagstore/src/iter.rs4
-rw-r--r--lib/core/libimagstore/src/lib.rs2
-rw-r--r--lib/core/libimagstore/src/store.rs134
-rw-r--r--lib/core/libimagstore/src/storeid.rs18
-rw-r--r--lib/core/libimagstore/src/util.rs13
22 files changed, 234 insertions, 280 deletions
diff --git a/lib/core/libimagerror/Cargo.toml b/lib/core/libimagerror/Cargo.toml
index 22b6eb8a..2cea7cbd 100644
--- a/lib/core/libimagerror/Cargo.toml
+++ b/lib/core/libimagerror/Cargo.toml
@@ -20,7 +20,8 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" }
maintenance = { status = "actively-developed" }
[dependencies]
-log = "0.4.6"
-ansi_term = "0.12"
-failure = "0.1.5"
-failure_derive = "0.1.5"
+log = "0.4.6"
+toml = "0.5"
+ansi_term = "0.12"
+thiserror = "1"
+anyhow = "1"
diff --git a/lib/core/libimagerror/src/errors.rs b/lib/core/libimagerror/src/errors.rs
index a1373d91..e74eedaf 100644
--- a/lib/core/libimagerror/src/errors.rs
+++ b/lib/core/libimagerror/src/errors.rs
@@ -17,88 +17,98 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
-#[derive(Debug, Clone, Eq, PartialEq, Fail)]
-pub enum ErrorMsg {
- #[fail(display = "IO Error")]
- IO,
+use thiserror::Error;
- #[fail(display = "Locking error")]
+pub type Result<T> = ::std::result::Result<T, Error>;
+
+#[derive(Debug, Error)]
+pub enum Error {
+ #[error("IO error")]
+ IO(#[from] ::std::io::Error),
+
+ #[error("Unknown IO error")]
+ UnknownIO,
+
+ #[error("Locking error")]
LockError,
- #[fail(display = "UTF8 error")]
- UTF8Error,
+ #[error("Locking error")]
+ PoisonError,
+
+ #[error("UTF8 error")]
+ UTF8Error(#[from] std::str::Utf8Error),
- #[fail(display = "Error in external process")]
+ #[error("Error in external process")]
ExternalProcessError,
- #[fail(display = "File Error")]
+ #[error("File Error")]
FileError,
- #[fail(display = "File not copied")]
+ #[error("File not copied")]
FileNotCopied,
- #[fail(display = "File not created")]
+ #[error("File not created")]
FileNotCreated,
- #[fail(display = "File not found")]
+ #[error("File not found")]
FileNotFound,
- #[fail(display = "Fail not removed")]
+ #[error("Fail not removed")]
FileNotRemoved,
- #[fail(display = "Fail not renamed")]
+ #[error("Fail not renamed")]
FileNotRenamed,
- #[fail(display = "File not seeked")]
+ #[error("File not seeked")]
FileNotSeeked,
- #[fail(display = "File not written")]
+ #[error("File not written")]
FileNotWritten,
- #[fail(display = "Directory not created")]
+ #[error("Directory not created")]
DirNotCreated,
- #[fail(display = "Formatting error")]
- FormatError,
+ #[error("Formatting error")]
+ FormatError(#[from] std::fmt::Error),
- #[fail(display = "ID is locked")]
+ #[error("ID is locked")]
IdLocked,
- #[fail(display = "Error while converting values")]
+ #[error("Error while converting values")]
ConversionError,
- #[fail(display = "Entry exists already: {}", _0)]
+ #[error("Entry exists already: {0}")]
EntryAlreadyExists(String),
- #[fail(display = "Entry not found: {}", _0)]
+ #[error("Entry not found: {0}")]
EntryNotFound(String),
- #[fail(display = "Entry header error")]
+ #[error("Entry header error")]
EntryHeaderError,
- #[fail(display = "Entry header type error")]
+ #[error("Entry header type error")]
EntryHeaderTypeError,
- #[fail(display = "Entry header type error at '{}', expected '{}'", _0, _1)]
+ #[error("Entry header type error at '{0}', expected '{1}'")]
EntryHeaderTypeError2(&'static str, &'static str),
- #[fail(display = "Entry header read error")]
+ #[error("Entry header read error")]
EntryHeaderReadError,
- #[fail(display = "Entry header write error")]
+ #[error("Entry header write error")]
EntryHeaderWriteError,
- #[fail(display = "Entry header field missing: {}", _0)]
+ #[error("Entry header field missing: {0}")]
EntryHeaderFieldMissing(&'static str),
- #[fail(display = "Toml deserialization error")]
+ #[error("Toml deserialization error")]
TomlDeserError,
- #[fail(display = "Toml querying error")]
+ #[error("Toml querying error")]
TomlQueryError,
}
diff --git a/lib/core/libimagerror/src/lib.rs b/lib/core/libimagerror/src/lib.rs
index 55d045a6..78d1e2c2 100644
--- a/lib/core/libimagerror/src/lib.rs
+++ b/lib/core/libimagerror/src/lib.rs
@@ -37,8 +37,9 @@
#[macro_use] extern crate log;
extern crate ansi_term;
-extern crate failure;
-#[macro_use] extern crate failure_derive;
+extern crate toml;
+extern crate thiserror;
+extern crate anyhow;
pub mod errors;
pub mod exit;
diff --git a/lib/core/libimagerror/src/trace.rs b/lib/core/libimagerror/src/trace.rs
index 1b192e44..e7bb5a39 100644
--- a/lib/core/libimagerror/src/trace.rs
+++ b/lib/core/libimagerror/src/trace.rs
@@ -18,48 +18,30 @@
//
use std::process::exit;
-use std::fmt::Display;
-use std::fmt::Formatter;
-use std::fmt::Result as FmtResult;
-use failure::Error;
-use ansi_term::Colour::Red;
-
-struct ImagTrace<'a, T: 'a + ?Sized>(&'a T);
-
-impl<'a, T: 'a + ?Sized> ImagTrace<'a, T> {
- fn new(d: &'a T) -> ImagTrace<'a, T> {
- ImagTrace(d)
- }
-}
-
-impl<'a> Display for ImagTrace<'a, Error>
-{
- fn fmt(&self, fmt: &mut Formatter) -> FmtResult {
- writeln!(fmt, "{}: {}", Red.blink().paint("ERROR[ 0]"), self.0)?;
-
- {
- for (i, cause) in self.0.iter_causes().enumerate() {
- writeln!(fmt,
- "{prefix}: {error}",
- prefix = Red.blink().paint(format!("ERROR[{:>4}]", i + 1)),
- error = cause)?;
- }
- }
-
- writeln!(fmt, "{}", Red.paint("--- BACKTRACE ---"))?;
- writeln!(fmt, "{:?}", self.0.backtrace())?;
-
- Ok(())
- }
-}
+use anyhow::Error;
+use ansi_term::Colour::Red;
pub fn trace_error(e: &Error) {
- eprintln!("{}", ImagTrace::new(e));
+ eprintln!("{}: {}", Red.blink().paint("ERROR[ 0]"), e);
+ let mut i = 0;
+ e.chain().skip(1).for_each(|cause| {
+ eprintln!("{prefix}: {error}",
+ prefix = Red.blink().paint(format!("ERROR[{:>4}]", i + 1)),
+ error = cause);
+ i += 1;
+ });
}
pub fn trace_error_dbg(e: &Error) {
- debug!("{}", ImagTrace::new(e));
+ debug!("{}: {}", Red.blink().paint("ERROR[ 0]"), e);
+ let mut i = 0;
+ e.chain().skip(1).for_each(|cause| {
+ debug!("{prefix}: {error}",
+ prefix = Red.blink().paint(format!("ERROR[{:>4}]", i + 1)),
+ error = cause);
+ i += 1;
+ });
}
/// Helper functions for `Result<T, E>` types to reduce overhead in the following situations:
diff --git a/lib/core/libimagrt/Cargo.toml b/lib/core/libimagrt/Cargo.toml
index 0a5f8841..d6792b51 100644
--- a/lib/core/libimagrt/Cargo.toml
+++ b/lib/core/libimagrt/Cargo.toml
@@ -26,8 +26,8 @@ xdg-basedir = "1.0.0"
itertools = "0.8.0"
ansi_term = "0.12"
atty = "0.2.11"
-failure = "0.1.5"
-failure_derive = "0.1.5"
+anyhow = "1"
+
serde_derive = "1.0.94"
serde = "1.0.94"
@@ -52,7 +52,8 @@ default-features = false
features = ["no_logging"]
[dependencies.toml-query]
-version = "0.9.2"
+git = "https://github.com/matthiasbeyer/toml-query"
+branch = "master"
default-features = false
features = [ "typed" ]
diff --git a/lib/core/libimagrt/src/application.rs b/lib/core/libimagrt/src/application.rs
index 3ff20d1f..cb5b9b26 100644
--- a/lib/core/libimagrt/src/application.rs
+++ b/lib/core/libimagrt/src/application.rs
@@ -19,7 +19,7 @@
use runtime::Runtime;
use clap::App;
-use failure::Fallible as Result;
+use anyhow::Result;
pub trait ImagApplication {
fn run(rt: Runtime) -> Result<()>;
@@ -34,10 +34,12 @@ pub trait ImagApplication {
macro_rules! simple_imag_application_binary {
($application_library:ident, $application_implementor:ident) => {
extern crate libimagerror;
- extern crate failure;
+ extern crate anyhow;
extern crate $application_library;
- use failure::{Error, Fallible as Result, ResultExt};
+ use anyhow::Error;
+ use anyhow::Result;
+ use anyhow::Context;
fn main() {
use libimagerror::trace::MapErrTrace;
diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs
index 000c20ba..7de02eb3 100644
--- a/lib/core/libimagrt/src/configuration.rs
+++ b/lib/core/libimagrt/src/configuration.rs
@@ -21,12 +21,12 @@ use std::path::PathBuf;
use toml::Value;
use clap::App;
-use failure::ResultExt;
-use failure::Fallible as Result;
-use failure::Error;
-use failure::err_msg;
+use anyhow::Context;
+use anyhow::Result;
+use anyhow::Error;
-use libimagerror::errors::ErrorMsg as EM;
+
+use libimagerror::errors::Error as EM;
/// Get a new configuration object.
///
@@ -119,18 +119,17 @@ pub fn override_config(val: &mut Value, v: Vec<String>) -> Result<()> {
None
}))
.map(|(k, v)| {
- let value = val.read_mut(&k)
- .context(EM::TomlQueryError)?
- .ok_or_else(|| err_msg("No config value there, cannot override."))?;
+ let value = val.read_mut(&k)?
+ .ok_or_else(|| anyhow!("No config value there, cannot override."))?;
let new_value = into_value(value, v)
- .ok_or_else(|| err_msg("Config override type not matching"))?;
+ .ok_or_else(|| anyhow!("Config override type not matching"))?;
info!("Successfully overridden: {} = {}", k, new_value);
*value = new_value;
Ok(())
})
- .map(|elem: Result<()>| elem.context(err_msg("Config override error")).map_err(Error::from))
+ .map(|elem: Result<()>| elem.context(anyhow!("Config override error")).map_err(Error::from))
.collect::<Result<()>>()
}
diff --git a/lib/core/libimagrt/src/iter.rs b/lib/core/libimagrt/src/iter.rs
index 519d6c65..153aa794 100644
--- a/lib/core/libimagrt/src/iter.rs
+++ b/lib/core/libimagrt/src/iter.rs
@@ -23,8 +23,8 @@ mod reporting {
use libimagstore::store::Entry;
use libimagstore::storeid::StoreId;
- use failure::Fallible as Result;
- use failure::Error;
+ use anyhow::Result;
+ use anyhow::Error;
use runtime::Runtime;
diff --git a/lib/core/libimagrt/src/lib.rs b/lib/core/libimagrt/src/lib.rs
index f7c9f579..c36e2d01 100644
--- a/lib/core/libimagrt/src/lib.rs
+++ b/lib/core/libimagrt/src/lib.rs
@@ -42,7 +42,7 @@ extern crate itertools;
extern crate ansi_term;
extern crate handlebars;
extern crate serde;
-#[macro_use] extern crate failure;
+#[macro_use] extern crate anyhow;
#[macro_use] extern crate toml_query;
extern crate clap;
diff --git a/lib/core/libimagrt/src/logger.rs b/lib/core/libimagrt/src/logger.rs
index c79f2ec2..73c23351 100644
--- a/lib/core/libimagrt/src/logger.rs
+++ b/lib/core/libimagrt/src/logger.rs
@@ -24,10 +24,9 @@ use std::sync::Arc;
use std::sync::Mutex;
use std::ops::Deref;
-use failure::ResultExt;
-use failure::Fallible as Result;
-use failure::Error;
-use failure::err_msg;
+use anyhow::Result;
+use anyhow::Error;
+
use clap::ArgMatches;
use log::{Log, Level, Record, Metadata};
use toml::Value;
@@ -35,8 +34,6 @@ use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use handlebars::Handlebars;
-use libimagerror::errors::ErrorMsg as EM;
-
#[derive(Debug)]
enum LogDestination {
Stderr,
@@ -152,7 +149,7 @@ fn match_log_level_str(s: &str) -> Result<Level> {
"info" => Ok(Level::Info),
"warn" => Ok(Level::Warn),
"error" => Ok(Level::Error),
- lvl => Err(format_err!("Invalid logging level: {}", lvl)),
+ lvl => Err(anyhow!("Invalid logging level: {}", lvl)),
}
}
@@ -175,10 +172,8 @@ fn aggregate_global_loglevel(matches: &ArgMatches, config: Option<&Value>) -> Re
if let Some(cfg) = config {
let cfg_loglevel = cfg
- .read_string("imag.logging.level")
- .map_err(Error::from)
- .context(EM::TomlQueryError)?
- .ok_or_else(|| err_msg("Global log level config missing"))
+ .read_string("imag.logging.level")?
+ .ok_or_else(|| anyhow!("Global log level config missing"))
.and_then(|s| match_log_level_str(&s))?;
if let Some(cli_loglevel) = get_arg_loglevel(matches)? {
@@ -208,8 +203,6 @@ fn translate_destination(raw: &str) -> Result<LogDestination> {
.map(Arc::new)
.map(LogDestination::File)
.map_err(Error::from)
- .context(EM::IO)
- .map_err(Error::from)
}
}
}
@@ -218,21 +211,18 @@ fn aggregate_global_destinations(config: Option<&Value>) -> Result<Vec<LogDestin
match config {
None => Ok(vec![LogDestination::default()]),
Some(cfg) => cfg
- .read("imag.logging.destinations")
- .map_err(Error::from)
- .context(EM::TomlQueryError)?
- .ok_or_else(|| err_msg("Global log destination config missing"))?
+ .read("imag.logging.destinations")?
+ .ok_or_else(|| anyhow!("Global log destination config missing"))?
.as_array()
.ok_or_else(|| {
let msg = "Type error at 'imag.logging.destinations', expected 'Array'";
- err_msg(msg)
+ anyhow!(msg)
})
.and_then(|raw| {
raw.iter()
.map(|val| {
val.as_str()
- .ok_or_else(|| "Type error at 'imag.logging.modules.<mod>.destinations', expected Array<String>")
- .map_err(err_msg)
+ .ok_or_else(|| anyhow!("Type error at 'imag.logging.modules.<mod>.destinations', expected Array<String>"))
.map_err(Error::from)
.and_then(|s| translate_destination(s))
})
@@ -242,29 +232,24 @@ fn aggregate_global_destinations(config: Option<&Value>) -> Result<Vec<LogDestin
}
mod log_lvl_aggregate {
- use failure::Fallible as Result;
- use failure::Error as E;
- use failure::ResultExt;
- use failure::err_msg;
+ use anyhow::Result;
+ use anyhow::Error as E;
+ use anyhow::Context;
use toml::Value;
use toml_query::read::TomlValueReadTypeExt;
use handlebars::Handlebars;
- use libimagerror::errors::ErrorMsg as EM;
-
macro_rules! aggregate_global_format_with {
($t:ident, $read_str:expr) => {
pub struct $t;
impl LogLevelAggregator for $t {
fn aggregate(config: Option<&Value>) -> Result<String> {
config.ok_or_else(|| {
- E::from(err_msg(concat!("Config missing: Logging format: ", stringify!($t))))
+ E::from(anyhow!(concat!("Config missing: Logging format: ", stringify!($t))))
})?
- .read_string($read_str)
- .map_err(E::from)
- .context(EM::TomlQueryError)?
+ .read_string($read_str)?
.ok_or_else(|| {
- E::from(err_msg(concat!("Config missing: Logging format: ", stringify!($t))))
+ E::from(anyhow!(concat!("Config missing: Logging format: ", stringify!($t))))
})
}
}
@@ -280,7 +265,7 @@ mod log_lvl_aggregate {
{
hb.register_template_string(lvlstr, T::aggregate(config)?)
.map_err(E::from)
- .context(err_msg("Handlebars template error"))
+ .context(anyhow!("Handlebars template error"))
.map_err(E::from)
}
diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs
index c29a2846..90ad0920 100644
--- a/lib/core/libimagrt/src/runtime.rs
+++ b/lib/core/libimagrt/src/runtime.rs
@@ -31,16 +31,15 @@ use toml::Value;
use toml_query::read::TomlValueReadExt;
use clap::{Arg, ArgMatches};
-use failure::ResultExt;
-use failure::Fallible as Result;
-use failure::Error;
-use failure::err_msg;
+use anyhow::Context;
+use anyhow::Result;
+use anyhow::Error;
+
use crate::configuration::{fetch_config, override_config, InternalConfiguration};
use crate::logger::ImagLogger;
use crate::io::OutputProxy;
-use libimagerror::errors::ErrorMsg as EM;
use libimagerror::trace::*;
use libimagstore::store::Store;
use libimagstore::storeid::StoreId;
@@ -85,10 +84,10 @@ impl<'a> Runtime<'a> {
let config = match fetch_config(&configpath)? {
None => {
- return Err(err_msg("No configuration file found"))
- .context(err_msg("Maybe try to use 'imag-init' to initialize imag?"))
- .context(err_msg("Continuing without configuration file"))
- .context(err_msg("Cannot instantiate runtime"))
+ return Err(anyhow!("No configuration file found"))
+ .context(anyhow!("Maybe try to use 'imag-init' to initialize imag?"))
+ .context(anyhow!("Continuing without configuration file"))
+ .context(anyhow!("Cannot instantiate runtime"))
.map_err(Error::from);
},
Some(mut config) => {
@@ -160,7 +159,7 @@ impl<'a> Runtime<'a> {
input_data,
output_data,
})
- .context(err_msg("Cannot instantiate runtime"))
+ .context(anyhow!("Cannot instantiate runtime"))
.map_err(Error::from)
}
@@ -389,15 +388,15 @@ impl<'a> Runtime<'a> {
.map(String::from)
.ok_or_else(|| {
self.config()
- .ok_or_else(|| err_msg("No Configuration!"))
+ .ok_or_else(|| anyhow!("No Configuration!"))
.and_then(|v| match v.read("rt.editor")? {
Some(&Value::String(ref s)) => Ok(Some(s.clone())),
- Some(_) => Err(err_msg("Type error at 'rt.editor', expected 'String'")),
+ Some(_) => Err(anyhow!("Type error at 'rt.editor', expected 'String'")),
None => Ok(None),
})
})
.or_else(|_| env::var("EDITOR"))
- .map_err(|_| Error::from(EM::IO))
+ .map_err(Error::from)
.and_then(|s| {
debug!("Editing with '{}'", s);
let mut split = s.split_whitespace();
@@ -407,7 +406,7 @@ impl<'a> Runtime<'a> {
}
let mut c = Command::new(command.unwrap()); // secured above
c.args(split);
- c.stdin(::std::fs::File::open("/dev/tty").context(EM::IO)?);
+ c.stdin(::std::fs::File::open("/dev/tty")?);
c.stderr(::std::process::Stdio::inherit());
Ok(Some(c))
})
@@ -500,7 +499,7 @@ impl<'a> Runtime<'a> {
let rtp_str = self.rtp()
.to_str()
.map(String::from)
- .ok_or_else(|| Error::from(EM::IO))?;
+ .ok_or_else(|| anyhow!("UTF8 Error: Runtimepath is not valid UTF8"))?;
let command = format!("{}-{}", command.as_ref(), subcommand.as_ref());
@@ -531,7 +530,6 @@ impl<'a> Runtime<'a> {
},
_ => e,
})
- .context(EM::IO)
.map_err(Error::from)
}
@@ -568,7 +566,7 @@ impl<'a> Runtime<'a> {
return if e.kind() == std::io::ErrorKind::BrokenPipe {
Ok(false)
} else {
- Err(failure::Error::from(e))
+ Err(Error::from(e))
}
}
}
@@ -675,7 +673,7 @@ pub fn get_rtp_match<'a>(matches: &ArgMatches<'a>) -> Result<PathBuf> {
match env::var("IMAG_RTP").map(PathBuf::from) {
Ok(p) => return Ok(p),
Err(env::VarError::NotUnicode(_)) => {
- return Err(err_msg("Environment variable 'IMAG_RTP' does not contain valid Unicode"))
+ return Err(anyhow!("Environment variable 'IMAG_RTP' does not contain valid Unicode"))
},
Err(env::VarError::NotPresent) => { /* passthrough */ }
}
@@ -685,10 +683,10 @@ pub fn get_rtp_match<'a>(matches: &ArgMatches<'a>) -> Result<PathBuf> {
.map(|mut p| { p.push(".imag"); p })
.map_err(|e| match e {
env::VarError::NotUnicode(_) => {
- err_msg("Environment variable 'HOME' does not contain valid Unicode")
+ anyhow!("Environment variable 'HOME' does not contain valid Unicode")
},
env::VarError::NotPresent => {
- err_msg("You seem to be $HOME-less. Please get a $HOME before using this \
+ anyhow!("You seem to be $HOME-less. Please get a $HOME before using this \
software. We are sorry for you and hope you have some \
accommodation anyways.")
}
diff --git a/lib/core/libimagstore/Cargo.toml b/lib/core/libimagstore/Cargo.toml
index f14f7c1b..6357b183 100644
--- a/lib/core/libimagstore/Cargo.toml
+++ b/lib/core/libimagstore/Cargo.toml
@@ -29,8 +29,8 @@ walkdir = "2.2.8"
is-match = "0.1.0"
serde = "1.0.94"
serde_json = "1.0.39"
-toml-query = "0.9.2"
-failure = "0.1.5"
+toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" }
+anyhow = "1"
libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
libimagutil = { version = "0.10.0", path = "../../../lib/etc/libimagutil" }
diff --git a/lib/core/libimagstore/src/configuration.rs b/lib/core/libimagstore/src/configuration.rs
index 44c21a72..a2b2e1de 100644
--- a/lib/core/libimagstore/src/configuration.rs
+++ b/lib/core/libimagstore/src/configuration.rs
@@ -19,11 +19,9 @@
use toml::Value;
-use failure::Fallible as Result;
-use failure::ResultExt;
-use failure::Error;
-
-use libimagerror::errors::ErrorMsg as EM;
+use anyhow::Result;
+use anyhow::Context;
+use anyhow::Error;
/// Checks whether the store configuration has a key "implicit-create" which maps to a boolean
/// value. If that key is present, the boolean is returned, otherwise false is returned.
@@ -34,10 +32,9 @@ pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bo
if let Some(ref t) = *config {
t.read_bool(key)
- .context(format_err!("Error reading header '{}' in configuration", key))
.map_err(Error::from)
- .context(EM::TomlQueryError)?
- .ok_or_else(|| format_err!("Config key missing: {}", key))
+ .context(anyhow!("Error reading header '{}' in configuration", key))?
+ .ok_or_else(|| anyhow!("Config key missing: {}", key))
} else {
Ok(false)
}
diff --git a/lib/core/libimagstore/src/file_abstraction/fs.rs b/lib/core/libimagstore/src/file_abstraction/fs.rs
index 5388a5c4..58350fca 100644
--- a/lib/core/libimagstore/src/file_abstraction/fs.rs
+++ b/lib/core/libimagstore/src/file_abstraction/fs.rs
@@ -22,8 +22,6 @@ use std::io::{Seek, SeekFrom, Read};
use std::path::{Path, PathBuf};
use std::sync::Arc;
-use libimagerror::errors::ErrorMsg as EM;
-
use super::FileAbstraction;
use super::FileAbstractionInstance;
use super::Drain;
@@ -33,9 +31,9 @@ use crate::file_abstraction::iter::PathIterator;
use crate::file_abstraction::iter::PathIterBuilder;
use walkdir::WalkDir;
-use failure::ResultExt;
-use failure::Fallible as Result;
-use failure::Error;
+use anyhow::Context;
+use anyhow::Result;
+use anyhow::Error;
#[derive(Debug)]
pub struct FSFileAbstractionInstance(PathBuf);
@@ -54,12 +52,11 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
Ok(Some(file)) => file,
};
- file.seek(SeekFrom::Start(0)).context(EM::FileNotSeeked)?;
+ file.seek(SeekFrom::Start(0))?;
let mut s = String::new();
file.read_to_string(&mut s)
- .context(EM::IO)
.map_err(Error::from)
.map(|_| s)
.and_then(|s: String| Entry::from_str(id, &s))
@@ -73,13 +70,12 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
use std::io::Write;
let buf = buf.to_str()?.into_bytes();
- let mut file = create_file(&self.0).context(EM::FileNotCreated)?;
+ let mut file = create_file(&self.0)?;
- file.seek(SeekFrom::Start(0)).context(EM::FileNotCreated)?;
- file.set_len(buf.len() as u64).context(EM::FileNotWritten)?;
- file.write_all(&buf)
- .context(EM::FileNotWritten)
- .map_err(Error::from)
+ file.seek(SeekFrom::Start(0))?;
+ file.set_len(buf.len() as u64)?;
+ file.write_all(&buf)?;
+ Ok(())
}
}
@@ -92,23 +88,18 @@ pub struct FSFileAbstraction {}
impl FileAbstraction for FSFileAbstraction {
fn remove_file(&self, path: &PathBuf) -> Result<()> {
- remove_file(path)
- .context(EM::FileNotRemoved)
- .map_err(Error::from)
+ remove_file(path).map_err(Error::from)
}
fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<()> {
- copy(from, to)
- .map(|_| ())
- .context(EM::FileNotCopied)
- .map_err(Error::from)
+ copy(from, to).map(|_| ()).map_err(Error::from)
}
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<()> {
if let Some(p) = to.parent() {
if !p.exists() {
debug!("Creating: {:?}", p);
- create_dir_all(&p).context(EM::DirNotCreated)?;
+ create_dir_all(&p)?;
}
} else {
debug!("Failed to find parent. This looks like it will fail now");
@@ -116,16 +107,12 @@ impl FileAbstraction for FSFileAbstraction {
}
debug!("Renaming {:?} to {:?}", from, to);
- rename(from, to)
- .context(EM::FileNotRenamed)
- .map_err(Error::from)
+ rename(from, to).map_err(Error::from)
}
fn create_dir_all(&self, path: &PathBuf) -> Result<()> {
debug!("Creating: {:?}", path);
- create_dir_all(path)
- .context(EM::DirNotCreated)
- .map_err(Error::from)
+ create_dir_all(path).map_err(Error::from)
}
fn exists(&self, path: &PathBuf) -> Result<bool> {
@@ -183,7 +170,7 @@ impl PathIterBuilder for WalkDirPathIterBuilder {
.map(|r| {
trace!("Working in PathIterator with {:?}", r);
r.map(|e| PathBuf::from(e.path()))
- .context(format_err!("Error in Walkdir"))
+ .context(anyhow!("Error in Walkdir"))
.map_err(Error::from)
}))
}
@@ -194,7 +181,7 @@ impl PathIterBuilder for WalkDirPathIterBuilder {
debug!(" -> path : {:?}", self.basepath);
if !self.basepath.exists() {
- Err(format_err!("Does not exist: {}", self.basepath.display()))
+ Err(anyhow!("Does not exist: {}", self.basepath.display()))
} else {
Ok(())
}
diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs
index 2deabcae..f6a0e289 100644
--- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs
+++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs
@@ -24,11 +24,11 @@ use std::cell::RefCell;
use std::sync::Arc;
use std::ops::Deref;
-use libimagerror::errors::ErrorMsg as EM;
+use libimagerror::errors::Error as EM;
+
+use anyhow::Result;
+use anyhow::Error;
-use failure::Fallible as Result;
-use failure::Error;
-use failure::err_msg;
use super::FileAbstraction;
use super::FileAbstractionInstance;
@@ -140,7 +140,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
let a = backend.remove(from).ok_or_else(|| EM::FileNotFound)?;
let new_entry = {
let new_location = if to.starts_with("/") {
- let s = to.to_str().map(String::from).ok_or_else(|| err_msg("Failed to convert path to str"))?;
+ let s = to.to_str().map(String::from).ok_or_else(|| anyhow!("Failed to convert path to str"))?;
PathBuf::from(s.replace("/", ""))
} else {
to.to_path_buf()
diff --git a/lib/core/libimagstore/src/file_abstraction/iter.rs b/lib/core/libimagstore/src/file_abstraction/iter.rs
index 14649ac9..e24177b1 100644
--- a/