Add information about which storeid is the cause of the error in errors

This commit is contained in:
Matthias Beyer 2018-04-30 18:37:52 +02:00
parent 76966bcd6c
commit 6a40ac6b98
2 changed files with 32 additions and 31 deletions

View file

@ -192,19 +192,19 @@ error_chain! {
display("StoreId has no 'base' part: {:?}", pb) display("StoreId has no 'base' part: {:?}", pb)
} }
CreateCallError { CreateCallError(sid: StoreId) {
description("Error when calling create()") description("Error when calling create()")
display("Error when calling create()") display("Error when calling create({:?})", sid)
} }
RetrieveCallError { RetrieveCallError(sid: StoreId) {
description("Error when calling retrieve()") description("Error when calling retrieve()")
display("Error when calling retrieve()") display("Error when calling retrieve({:?})", sid)
} }
GetCallError { GetCallError(sid: StoreId) {
description("Error when calling get()") description("Error when calling get()")
display("Error when calling get()") display("Error when calling get({:?})", sid)
} }
GetAllVersionsCallError { GetAllVersionsCallError {
@ -217,24 +217,24 @@ error_chain! {
display("Error when calling retrieve_for_module()") display("Error when calling retrieve_for_module()")
} }
UpdateCallError { UpdateCallError(sid: StoreId) {
description("Error when calling update()") description("Error when calling update()")
display("Error when calling update()") display("Error when calling update({:?})", sid)
} }
RetrieveCopyCallError { RetrieveCopyCallError(sid: StoreId) {
description("Error when calling retrieve_copy()") description("Error when calling retrieve_copy()")
display("Error when calling retrieve_copy()") display("Error when calling retrieve_copy({:?})", sid)
} }
DeleteCallError { DeleteCallError(sid: StoreId) {
description("Error when calling delete()") description("Error when calling delete()")
display("Error when calling delete()") display("Error when calling delete({:?})", sid)
} }
MoveCallError { MoveCallError(old: StoreId, new: StoreId) {
description("Error when calling move()") description("Error when calling move()")
display("Error when calling move()") display("Error when calling move({:?} -> {:?})", old, new)
} }
MoveByIdCallError { MoveByIdCallError {

View file

@ -327,7 +327,7 @@ impl Store {
.read() .read()
.map(|map| map.contains_key(&id)) .map(|map| map.contains_key(&id))
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.chain_err(|| SEK::CreateCallError)?; .chain_err(|| SEK::CreateCallError(id.clone()))?;
if exists { if exists {
debug!("Entry exists: {:?}", id); debug!("Entry exists: {:?}", id);
@ -339,12 +339,12 @@ impl Store {
.entries .entries
.write() .write()
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.chain_err(|| SEK::CreateCallError)?; .chain_err(|| SEK::CreateCallError(id.clone()))?;
if hsmap.contains_key(&id) { if hsmap.contains_key(&id) {
debug!("Cannot create, internal cache already contains: '{}'", id); debug!("Cannot create, internal cache already contains: '{}'", id);
return Err(SE::from_kind(SEK::EntryAlreadyExists(id.clone()))) return Err(SE::from_kind(SEK::EntryAlreadyExists(id.clone())))
.chain_err(|| SEK::CreateCallError); .chain_err(|| SEK::CreateCallError(id.clone()));
} }
hsmap.insert(id.clone(), { hsmap.insert(id.clone(), {
debug!("Creating: '{}'", id); debug!("Creating: '{}'", id);
@ -387,7 +387,7 @@ impl Store {
se.status = StoreEntryStatus::Borrowed; se.status = StoreEntryStatus::Borrowed;
entry entry
}) })
.chain_err(|| SEK::RetrieveCallError)?; .chain_err(|| SEK::RetrieveCallError(id.clone()))?;
debug!("Constructing FileLockEntry: '{}'", id); debug!("Constructing FileLockEntry: '{}'", id);
Ok(FileLockEntry::new(self, entry)) Ok(FileLockEntry::new(self, entry))
@ -412,14 +412,14 @@ impl Store {
.read() .read()
.map(|map| map.contains_key(&id)) .map(|map| map.contains_key(&id))
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.chain_err(|| SEK::GetCallError)?; .chain_err(|| SEK::GetCallError(id.clone()))?;
if !exists { if !exists {
debug!("Does not exist in internal cache or filesystem: {:?}", id); debug!("Does not exist in internal cache or filesystem: {:?}", id);
return Ok(None); return Ok(None);
} }
self.retrieve(id).map(Some).chain_err(|| SEK::GetCallError) self.retrieve(id.clone()).map(Some).chain_err(|| SEK::GetCallError(id))
} }
/// Walk the store tree for the module /// Walk the store tree for the module
@ -445,7 +445,7 @@ impl Store {
/// ///
pub fn update<'a>(&'a self, entry: &mut FileLockEntry<'a>) -> Result<()> { pub fn update<'a>(&'a self, entry: &mut FileLockEntry<'a>) -> Result<()> {
debug!("Updating FileLockEntry at '{}'", entry.get_location()); debug!("Updating FileLockEntry at '{}'", entry.get_location());
self._update(entry, false).chain_err(|| SEK::UpdateCallError) self._update(entry, false).chain_err(|| SEK::UpdateCallError(entry.get_location().clone()))
} }
/// Internal method to write to the filesystem store. /// Internal method to write to the filesystem store.
@ -493,11 +493,11 @@ impl Store {
debug!("Retrieving copy of '{}'", id); debug!("Retrieving copy of '{}'", id);
let entries = self.entries.write() let entries = self.entries.write()
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.chain_err(|| SEK::RetrieveCopyCallError)?; .chain_err(|| SEK::RetrieveCopyCallError(id.clone()))?;
// if the entry is currently modified by the user, we cannot drop it // 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) { if entries.get(&id).map(|e| e.is_borrowed()).unwrap_or(false) {
return Err(SE::from_kind(SEK::IdLocked)).chain_err(|| SEK::RetrieveCopyCallError); return Err(SE::from_kind(SEK::IdLocked)).chain_err(|| SEK::RetrieveCopyCallError(id));
} }
StoreEntry::new(id, &self.backend)?.get_entry() StoreEntry::new(id, &self.backend)?.get_entry()
@ -524,7 +524,7 @@ impl Store {
.entries .entries
.write() .write()
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.chain_err(|| SEK::DeleteCallError)?; .chain_err(|| SEK::DeleteCallError(id.clone()))?;
// if the entry is currently modified by the user, we cannot drop it // if the entry is currently modified by the user, we cannot drop it
match entries.get(&id) { match entries.get(&id) {
@ -536,7 +536,7 @@ impl Store {
// StoreId::exists(), a PathBuf object gets allocated. So we simply get a // StoreId::exists(), a PathBuf object gets allocated. So we simply get a
// PathBuf here, check whether it is there and if it is, we can re-use it to // PathBuf here, check whether it is there and if it is, we can re-use it to
// delete the filesystem file. // delete the filesystem file.
let pb = id.into_pathbuf()?; let pb = id.clone().into_pathbuf()?;
if pb.exists() { if pb.exists() {
// looks like we're deleting a not-loaded file from the store. // looks like we're deleting a not-loaded file from the store.
@ -545,11 +545,12 @@ impl Store {
} else { } else {
debug!("Seems like {:?} is not even on the FS", pb); debug!("Seems like {:?} is not even on the FS", pb);
return Err(SE::from_kind(SEK::FileNotFound)) return Err(SE::from_kind(SEK::FileNotFound))
.chain_err(|| SEK::DeleteCallError) .chain_err(|| SEK::DeleteCallError(id))
} }
}, },
Some(e) => if e.is_borrowed() { Some(e) => if e.is_borrowed() {
return Err(SE::from_kind(SEK::IdLocked)).chain_err(|| SEK::DeleteCallError) return Err(SE::from_kind(SEK::IdLocked))
.chain_err(|| SEK::DeleteCallError(id))
} }
} }
@ -560,7 +561,7 @@ impl Store {
.backend .backend
.remove_file(&pb) .remove_file(&pb)
.chain_err(|| SEK::FileError) .chain_err(|| SEK::FileError)
.chain_err(|| SEK::DeleteCallError)?; .chain_err(|| SEK::DeleteCallError(id))?;
} }
debug!("Deleted"); debug!("Deleted");
@ -588,11 +589,11 @@ impl Store {
.entries .entries
.write() .write()
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.chain_err(|| SEK::MoveCallError)?; .chain_err(|| SEK::MoveCallError(entry.get_location().clone(), new_id.clone()))?;
if hsmap.contains_key(&new_id) { if hsmap.contains_key(&new_id) {
return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone()))) return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone())))
.chain_err(|| SEK::MoveCallError) .chain_err(|| SEK::MoveCallError(entry.get_location().clone(), new_id.clone()))
} }
let old_id = entry.get_location().clone(); let old_id = entry.get_location().clone();
@ -608,7 +609,7 @@ impl Store {
Ok(()) Ok(())
}) })
.chain_err(|| SEK::FileError) .chain_err(|| SEK::FileError)
.chain_err(|| SEK::MoveCallError) .chain_err(|| SEK::MoveCallError(old_id, new_id))
} }
/// Move an entry without loading /// Move an entry without loading