diff --git a/imag-store/Cargo.toml b/imag-store/Cargo.toml index 66648cb1..13e8ebae 100644 --- a/imag-store/Cargo.toml +++ b/imag-store/Cargo.toml @@ -34,3 +34,6 @@ path = "../libimagutil" [dependencies.libimagerror] path = "../libimagerror" +[features] +early-panic = [ "libimagstore/early-panic" ] + diff --git a/libimagstore/Cargo.toml b/libimagstore/Cargo.toml index 656092f5..08d9f5ec 100644 --- a/libimagstore/Cargo.toml +++ b/libimagstore/Cargo.toml @@ -39,3 +39,8 @@ env_logger = "0.3" default = [] verify = [] +# Enable panic!()s if critical errors occur. +# Can be used to debug the store more intensly via the imag-store commandline +# application +early-panic=[] + diff --git a/libimagstore/src/lib.rs b/libimagstore/src/lib.rs index a420b5f1..56c3a742 100644 --- a/libimagstore/src/lib.rs +++ b/libimagstore/src/lib.rs @@ -46,6 +46,8 @@ extern crate walkdir; #[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagutil; +#[macro_use] mod util; + pub mod storeid; pub mod error; pub mod hook; diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 43914331..d245feb3 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -942,7 +942,15 @@ impl<'a> DerefMut for FileLockEntry<'a> { impl<'a> Drop for FileLockEntry<'a> { /// This will silently ignore errors, use `Store::update` if you want to catch the errors fn drop(&mut self) { - let _ = self.store._update(self, true); + use libimagerror::trace::trace_error_dbg; + + match self.store._update(self, true) { + Err(e) => { + trace_error_dbg(&e); + if_cfg_panic!("ERROR WHILE DROPPING: {:?}", e); + }, + Ok(_) => { }, + } } } diff --git a/libimagstore/src/util.rs b/libimagstore/src/util.rs new file mode 100644 index 00000000..9ff4a145 --- /dev/null +++ b/libimagstore/src/util.rs @@ -0,0 +1,35 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +#[cfg(feature = "early-panic")] +#[macro_export] +macro_rules! if_cfg_panic { + () => { panic!() }; + ($msg:expr) => { panic!($msg) }; + ($fmt:expr, $($arg:tt)+) => { panic!($fmt, $($($arg),*)) }; +} + +#[cfg(not(feature = "early-panic"))] +#[macro_export] +macro_rules! if_cfg_panic { + () => { }; + ($msg:expr) => { }; + ($fmt:expr, $($arg:tt)+) => { }; +} +