summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagstore/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/libimagstore/src')
-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
10 files changed, 109 insertions, 134 deletions
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/lib/core/libimagstore/src/file_abstraction/iter.rs
+++ b/lib/core/libimagstore/src/file_abstraction/iter.rs
@@ -21,7 +21,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::fmt::Debug;
-use failure::Fallible as Result;
+use anyhow::Result;
use crate::storeid::StoreIdWithBase;
use crate::file_abstraction::FileAbstraction;
diff --git a/lib/core/libimagstore/src/file_abstraction/mod.rs b/lib/core/libimagstore/src/file_abstraction/mod.rs
index f277e0cf..a46151d6 100644
--- a/lib/core/libimagstore/src/file_abstraction/mod.rs
+++ b/lib/core/libimagstore/src/file_abstraction/mod.rs
@@ -22,7 +22,7 @@ use std::fmt::Debug;
use std::collections::HashMap;
use std::sync::Arc;
-use failure::Fallible as Result;
+use anyhow::Result;
use crate::store::Entry;
use crate::storeid::StoreIdWithBase;
diff --git a/lib/core/libimagstore/src/iter.rs b/lib/core/libimagstore/src/iter.rs
index 060dc791..cd0b1ad2 100644
--- a/lib/core/libimagstore/src/iter.rs
+++ b/lib/core/libimagstore/src/iter.rs
@@ -31,7 +31,7 @@ macro_rules! mk_iterator_mod {
#[allow(unused_imports)]
use crate::store::FileLockEntry;
use crate::store::Store;
- use failure::Fallible as Result;
+ use anyhow::Result;
pub struct $itername<'a>(Box<dyn Iterator<Item = Result<StoreId>> + 'a>, &'a Store);
@@ -144,7 +144,7 @@ use self::get::StoreGetIterator;
use self::retrieve::StoreRetrieveIterator;
use crate::file_abstraction::iter::PathIterator;
use crate::store::Store;
-use failure::Fallible as Result;
+use anyhow::Result;
/// Iterator for iterating over all (or a subset of all) entries
///
diff --git a/lib/core/libimagstore/src/lib.rs b/lib/core/libimagstore/src/lib.rs
index 754647d0..a7a4be3d 100644
--- a/lib/core/libimagstore/src/lib.rs
+++ b/lib/core/libimagstore/src/lib.rs
@@ -46,7 +46,7 @@ extern crate semver;
extern crate walkdir;
#[macro_use] extern crate is_match;
extern crate serde_json;
-#[macro_use] extern crate failure;
+#[macro_use] extern crate anyhow;
extern crate toml_query;
extern crate libimagerror;
diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs
index e5748121..79eb5b3e 100644
--- a/lib/core/libimagstore/src/store.rs
+++ b/lib/core/libimagstore/src/store.rs
@@ -30,15 +30,15 @@ use std::fmt::Formatter;
use std::fmt::Debug;
use std::fmt::Error as FMTError;
-use libimagerror::errors::ErrorMsg as EM;
+use libimagerror::errors::Error as EM;
use toml::Value;
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
-use failure::Fallible as Result;
-use failure::ResultExt;
-use failure::err_msg;
-use failure::Error;
+use anyhow::Result;
+use anyhow::Context;
+
+use anyhow::Error;
use crate::storeid::{IntoStoreId, StoreId};
use crate::iter::Entries;
@@ -70,9 +70,7 @@ impl StoreEntry {
#[cfg(feature = "fs-lock")]
{
- open_file(pb.clone())
- .and_then(|f| f.lock_exclusive())
- .with_context(|| EM::IO)?;
+ open_file(pb.clone()).and_then(|f| f.lock_exclusive())?;
}
Ok(StoreEntry {
@@ -96,7 +94,7 @@ impl StoreEntry {
None => Ok(Entry::new(self.id.clone()))
}
} else {
- Err(format_err!("EntryAlreadyBorrowed: {}", self.id))
+ Err(anyhow!("EntryAlreadyBorrowed: {}", self.id))
}
}
@@ -188,18 +186,15 @@ impl Store {
debug!("Building new Store object");
if !location.exists() {
if !config_implicit_store_create_allowed(store_config)? {
- return Err(format_err!("CreateStoreDirDenied"))
- .context(EM::FileError)
- .context(EM::IO)
- .map_err(Error::from)
+ return Err(anyhow!("CreateStoreDirDenied"));
}
backend
.create_dir_all(&location)
- .context(format_err!("StorePathCreate: {}", location.display()))?;
+ .context(anyhow!("StorePathCreate: {}", location.display()))?;
} else if location.is_file() {
debug!("Store path exists as file");
- return Err(format_err!("StorePathExists: {}", location.display()));
+ return Err(anyhow!("StorePathExists: {}", location.display()));
}
let store = Store {
@@ -222,8 +217,8 @@ impl Store {
self.entries
.read()
- .map_err(|_| Error::from(EM::LockError))
- .context(format_err!("Error while checking whether {} is borrowed", id))
+ .map_err(|_| EM::LockError)
+ .context(anyhow!("Error while checking whether {} is borrowed", id))
.map(|cache| cache.get(&id).map(|e| e.is_borrowed()).unwrap_or(false))
.map_err(Error::from)
}
@@ -243,20 +238,20 @@ impl Store {
if exists {
debug!("Entry exists: {:?}", id);
- return Err(format_err!("EntryAlreadyExists: {}", id));
+ return Err(anyhow!("EntryAlreadyExists: {}", id));
}
{
let mut hsmap = self
.entries
.write()
- .map_err(|_| Error::from(EM::LockError))
- .context(format_err!("CreateCallError: {}", id))?;
+ .map_err(|_| EM::LockError)
+ .context(anyhow!("CreateCallError: {}", id))?;
if hsmap.contains_key(&id) {
debug!("Cannot create, internal cache already contains: '{}'", id);
- return Err(format_err!("EntryAlreadyExists: {}", id))
- .context(format_err!("CreateCallError: {}", id))
+ return Err(anyhow!("EntryAlreadyExists: {}", id))
+ .context(anyhow!("CreateCallError: {}", id))
.map_err(Error::from)
}
hsmap.insert(id.clone(), {
@@ -288,7 +283,8 @@ impl Store {
let entry = self
.entries
.write()
- .map_err(|_| Error::from(EM::LockError))
+ .map_err(|_| EM::LockError)
+ .map_err(Error::from)
.and_then(|mut es| {
let new_se = StoreEntry::new(self.path().clone(), id.clone(), &self.backend)?;
let se = es.entry(id.clone()).or_insert(new_se);
@@ -296,7 +292,7 @@ impl Store {
se.status = StoreEntryStatus::Borrowed;
entry
})
- .context(format_err!("RetrieveCallError: {}", id))?;
+ .context(anyhow!("RetrieveCallError: {}", id))?;
debug!("Constructing FileLockEntry: '{}'", id);
Ok(FileLockEntry::new(self, entry))
@@ -326,7 +322,7 @@ impl Store {
self.retrieve(id.clone())
.map(Some)
- .context(format_err!("GetCallError: {}", id))
+ .context(anyhow!("GetCallError: {}", id))
.map_err(Error::from)
}
@@ -339,7 +335,7 @@ impl Store {
pub fn update<'a>(&'a self, entry: &mut FileLockEntry<'a>) -> Result<()> {
debug!("Updating FileLockEntry at '{}'", entry.get_location());
self._update(entry, false)
- .context(format_err!("UpdateCallError: {}", entry.get_location()))
+ .context(anyhow!("UpdateCallError: {}", entry.get_location()))
.map_err(Error::from)
}
@@ -351,8 +347,7 @@ impl Store {
/// it is not public.
///
fn _update<'a>(&'a self, entry: &mut FileLockEntry<'a>, modify_presence: bool) -> Result<()> {
- let mut hsmap = self.entries.write()
- .map_err(|_| Error::from(EM::LockError))?;
+ let mut hsmap = self.entries.write().map_err(|_| EM::LockError)?;
let se = hsmap.get_mut(&entry.location).ok_or_else(|| {
EM::EntryNotFound(entry.location.local_display_string())
@@ -388,8 +383,7 @@ impl Store {
pub fn flush_cache(&self) -> Result<()> {
// We borrow this early so that between the aggregation of the flushables and the actual
// flush, there is no borrowing from the store.
- let mut hsmap = self.entries.write()
- .map_err(|_| Error::from(EM::LockError))?;
+ let mut hsmap = self.entries.write().map_err(|_| EM::LockError)?;
let mut to_flush = vec![];
for (storeid, se) in hsmap.deref() {
@@ -409,13 +403,17 @@ impl Store {
/// The number of elements in the internal cache
pub fn cache_size(&self) -> Result<usize> {
- let hsmap = self.entries.read().map_err(|_| Error::from(EM::LockError))?;
+ let hsmap = self.entries
+ .read()
+ .map_err(|_| EM::LockError)?;
Ok(hsmap.iter().count())
}
/// The size of the internal cache
pub fn cache_capacity(&self) -> Result<usize> {
- let hsmap = self.entries.read().map_err(|_| Error::from(EM::LockError))?;
+ let hsmap = self.entries
+ .read()
+ .map_err(|_| EM::LockError)?;
Ok(hsmap.capacity())
}
@@ -428,14 +426,15 @@ impl Store {
pub fn get_copy<S: IntoStoreId>(&self, id: S) -> Result<Entry> {
let id = id.into_storeid()?;
debug!("Retrieving copy of '{}'", id);
- let entries = self.entries.write()
- .map_err(|_| Error::from(EM::LockError))
- .context(format_err!("RetrieveCopyCallError: {}", id))?;
+ let entries = self.entries
+ .write()
+ .map_err(|_| EM::LockError)
+ .context(anyhow!("RetrieveCopyCallError: {}", id))?;
// if the entry is currently modified by the user, we cannot drop it
if entries.get(&id).map(|e| e.is_borrowed()).unwrap_or(false) {
return Err(EM::IdLocked)
- .context(format_err!("RetrieveCopyCallError: {}", id))
+ .context(anyhow!("RetrieveCopyCallError: {}", id))
.map_err(Error::from)
}
@@ -463,13 +462,13 @@ impl Store {
let mut entries = self
.entries
.write()
- .map_err(|_| Error::from(EM::LockError))
- .context(format_err!("DeleteCallError: {}", id))?;
+ .map_err(|_| EM::LockError)
+ .context(anyhow!("DeleteCallError: {}", id))?;
let do_remove = match entries.get(&id) {
Some(e) => if e.is_borrowed() { // entry is currently borrowed, we cannot delete it
return Err(Error::from(EM::LockError))
- .context(format_err!("DeleteCallError: {}", id))
+ .context(anyhow!("DeleteCallError: {}", id))
.map_err(Error::from)
// false
} else { // Entry is in the cache
@@ -484,7 +483,7 @@ impl Store {
if !self.backend.exists(&pb)? {
debug!("Seems like {:?} is not even on the FS", pb);
return Err(EM::FileNotFound)
- .context(format_err!("DeleteCallError: {}", id))
+ .context(anyhow!("DeleteCallError: {}", id))
.map_err(Error::from)
} // else { continue }
@@ -501,8 +500,8 @@ impl Store {
self
.backend
.remove_file(&pb)
- .context(EM::FileError)
- .context(format_err!("DeleteCallError: {}", id))?;
+ .map_err(Error::from)
+ .context(anyhow!("DeleteCallError: {}", id))?;
debug!("Deleted");
Ok(())
@@ -527,12 +526,12 @@ impl Store {
let hsmap = self
.entries
.write()
- .map_err(|_| Error::from(EM::LockError))
- .context(format_err!("MoveCallError: {} -> {}", entry.get_location(), new_id))?;
+ .map_err(|_| EM::LockError)
+ .context(anyhow!("MoveCallError: {} -> {}", entry.get_location(), new_id))?;
if hsmap.contains_key(&new_id) {
- return Err(format_err!("Entry exists already: {}", new_id.clone()))
- .context(format_err!("MoveCallError: {} -> {}", entry.get_location(), new_id))
+ return Err(anyhow!("Entry exists already: {}", new_id.clone()))
+ .context(anyhow!("MoveCallError: {} -> {}", entry.get_location(), new_id))
.map_err(Error::from)
}
@@ -548,8 +547,7 @@ impl Store {
} else {
Ok(())
})
- .context(EM::FileError)
- .context(format_err!("MoveCallError: {} -> {}", old_id, new_id))
+ .context(anyhow!("MoveCallError: {} -> {}", old_id, new_id))
.map_err(Error::from)
}
@@ -591,10 +589,10 @@ impl Store {
{
let mut hsmap = self.entries.write()
- .map_err(|_| Error::from(EM::LockError))?;
+ .map_err(|_| EM::LockError)?;
if hsmap.contains_key(&new_id) {
- return Err(format_err!("Entry already exists: {}", new_id));
+ return Err(anyhow!("Entry already exists: {}", new_id));
}
debug!("New id does not exist in cache");
@@ -602,7 +600,7 @@ impl Store {
let new_id_pb = new_id.clone().with_base(self.path()).into_pathbuf()?;
if !self.backend.exists(&old_id_pb)? {
- return Err(format_err!("Entry does not exist: {}", old_id));
+ return Err(anyhow!("Entry does not exist: {}", old_id));
}
// if it is borrowed, we really should not rename it, as this might
@@ -610,11 +608,11 @@ impl Store {
//
// Also, remove this object from the cache
if hsmap.remove(&old_id).map(|e| e.is_borrowed()).unwrap_or(false) {
- return Err(format_err!("Entry already borrowed: {}", old_id));
+ return Err(anyhow!("Entry already borrowed: {}", old_id));
}
if self.backend.exists(&new_id_pb)? {
- return Err(format_err!("Entry already exists: {}", new_id));
+ return Err(anyhow!("Entry already exists: {}", new_id));
}
debug!("New entry does not yet exist on filesystem. Good.");
@@ -624,7 +622,7 @@ impl Store {
.context({
let old = old_id_pb.display().to_string();
let new = new_id_pb.display().to_string();
- format_err!("Rename error: {} -> {}", old, new)
+ anyhow!("Rename error: {} -> {}", old, new)
})?;
debug!("Rename worked on filesystem");
@@ -647,9 +645,9 @@ impl Store {
let cache_has_entry = |id: &StoreId|
self.entries
.read()
+ .map_err(|_| EM::LockError)
.map(|map| map.contains_key(id))
- .map_err(|_| Error::from(EM::LockError))
- .context(format_err!("CreateCallError: {}", id));
+ .context(anyhow!("CreateCallError: {}", id));
let backend_has_entry = |id: StoreId|
self.backend.exists(&id.with_base(self.path()).into_pathbuf()?);
@@ -795,7 +793,7 @@ impl Entry {
pub fn from_reader<S: IntoStoreId>(loc: S, file: &mut dyn Read) -> Result<Entry> {
let text = {
let mut s = String::new();
- file.read_to_string(&mut s).context(EM::IO)?;
+ file.read_to_string(&mut s)?;
s
};
Self::from_str(loc, &text[..])
@@ -833,7 +831,7 @@ impl Entry {
Ok(format!("---\n{header}---\n{content}",
header = ::toml::ser::to_string_pretty(&self.header)
.map_err(Error::from)
- .context(err_msg("TOML Error"))?,
+ .context(anyhow!("TOML Error"))?,
content = self.content))
}
@@ -882,12 +880,12 @@ impl Entry {
/// Currently, this only verifies the header. This might change in the future.
pub fn verify(&self) -> Result<()> {
if !has_main_section(&self.header)? {
- Err(format_err!("MissingMainSection"))
+ Err(anyhow!("MissingMainSection"))
} else if !has_imag_version_in_main_section(&self.header)? {
- Err(format_err!("MissingVersionInfo"))
+ Err(anyhow!("MissingVersionInfo"))
} else if !has_only_tables(&self.header)? {
debug!("Could not verify that it only has tables in its base table");
- Err(format_err!("NonTableInBaseTable"))
+ Err(anyhow!("NonTableInBaseTable"))
} else {
Ok(())
}
@@ -909,23 +907,19 @@ fn has_only_tables(t: &Value) -> Result<bool> {
debug!("Verifying that table has only tables");
match *t {
Value::Table(ref tab) => Ok(tab.iter().all(|(_, x)| is_match!(*x, Value::Table(_)))),
- _ => Err(format_err!("HeaderTypeFailure")),
+ _ => Err(anyhow!("HeaderTypeFailure")),
}
}
fn has_main_section(t: &Value) -> Result<bool> {
- t.read("imag")
- .map_err(Error::from)
- .context(EM::TomlQueryError)?
- .ok_or_else(|| format_err!("ConfigKeyMissingError('imag')"))
+ t.read("imag")?
+ .ok_or_else(|| anyhow!("ConfigKeyMissingError('imag')"))
.map(Value::is_table)
}
fn has_imag_version_in_main_section(t: &Value) -> Result<bool> {
- t.read_string("imag.version")
- .map_err(Error::from)
- .context(EM::TomlQueryError)?
- .ok_or_else(|| format_err!("ConfigKeyMissingError('imag.version')"))
+ t.read_string("imag.version")?
+ .ok_or_else(|| anyhow!("ConfigKeyMissingError('imag.version')"))
.map_err(Error::from)
.map(String::from)
.map(|s: String| ::semver::Version::parse(&s).is_ok())
diff --git a/lib/core/libimagstore/src/storeid.rs b/lib/core/libimagstore/src/storeid.rs
index 3972f376..22f15734 100644
--- a/lib/core/libimagstore/src/storeid.rs
+++ b/lib/core/libimagstore/src/storeid.rs
@@ -26,10 +26,10 @@ use std::fmt::Error as FmtError;
use std::result::Result as RResult;
use std::path::Components;
-use failure::ResultExt;
-use failure::Fallible as Result;
-use failure::err_msg;
-use failure::Error;
+use anyhow::Context;
+use anyhow::Result;
+
+use anyhow::Error;
use crate::store::Store;
@@ -52,7 +52,7 @@ impl StoreId {
debug!("Trying to get a new baseless id from: {:?}", id);
if id.is_absolute() {
debug!("Error: Id is absolute!");
- Err(format_err!("Store Id local part is absolute: {}", id.display()))
+ Err(anyhow!("Store Id local part is absolute: {}", id.display()))
} else {
debug!("Building Storeid object baseless");
Ok(StoreId(id))
@@ -184,11 +184,11 @@ impl<'a> StoreIdWithBase<'a> {
store_part.display());
let p = full_path
.strip_prefix(store_part)
- .context(format_err!("Cannot strip prefix '{}' from path: '{}'",
+ .context(anyhow!("Cannot strip prefix '{}' from path: '{}'",
store_part.display(),
full_path.display()))
.map_err(Error::from)
- .context(err_msg("Error building Store Id from full path"))?;
+ .context(anyhow!("Error building Store Id from full path"))?;
Ok(StoreIdWithBase(store_part, PathBuf::from(p)))
}
}
@@ -227,7 +227,7 @@ macro_rules! module_entry_path_mod {
use std::path::Path;
use std::path::PathBuf;
use $crate::storeid::StoreId;
- use failure::Fallible as Result;
+ use anyhow::Result;
pub fn new_id<P: AsRef<Path>>(p: P) -> Result<StoreId> {
@@ -235,7 +235,7 @@ macro_rules! module_entry_path_mod {
.as_ref()
.to_str()
.ok_or_else(|| {
- format_err!("File path is not valid UTF-8: {}", p.as_ref().display())
+ anyhow!("File path is not valid UTF-8: {}", p.as_ref().display())
})?;
let id = format!("{}/{}", $name, path_str);
diff --git a/lib/core/libimagstore/src/util.rs b/lib/core/libimagstore/src/util.rs
index 946cfd94..e113b14c 100644
--- a/lib/core/libimagstore/src/util.rs
+++ b/lib/core/libimagstore/src/util.rs
@@ -20,10 +20,7 @@
use std::fmt::Write;
use toml::Value;
-use failure::Fallible as Result;
-use failure::ResultExt;
-
-use libimagerror::errors::ErrorMsg as EM;
+use anyhow::Result;
#[cfg(feature = "early-panic")]
#[macro_export]
@@ -55,15 +52,15 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> {
header_consumed = true;
// do not further process the line
} else if !header_consumed {
- writeln!(header, "{}", line).context(EM::FormatError)?;
+ writeln!(header, "{}", line)?;
} else if iter.peek().is_some() {
- writeln!(content, "{}", line).context(EM::FormatError)?;
+ writeln!(content, "{}", line)?;
} else {
- write!(content, "{}", line).context(EM::FormatError)?;
+ write!(content, "{}", line)?;
}
}
- let h = ::toml::de::from_str(&header).context(EM::TomlDeserError)?;
+ let h = ::toml::de::from_str(&header)?;
Ok((h, content))
}