summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-02-04 20:56:30 +0100
committerMatthias Beyer <mail@beyermatthias.de>2017-02-05 13:10:39 +0100
commite8f4a9089a7c87c0b25c1d9dc395a8a3cb38b72b (patch)
tree11d70fe1d69636222c5da5bd23a64876b57dbbb7
parent7b3f28eb0aaffd8c2429dfc01cadf6c54d2070e6 (diff)
downloadimag-e8f4a9089a7c87c0b25c1d9dc395a8a3cb38b72b.zip
imag-e8f4a9089a7c87c0b25c1d9dc395a8a3cb38b72b.tar.gz
Add feature to compile early panics
Do debug printing when drop of FileLockEntry failed.
-rw-r--r--imag-store/Cargo.toml3
-rw-r--r--libimagstore/Cargo.toml5
-rw-r--r--libimagstore/src/lib.rs2
-rw-r--r--libimagstore/src/store.rs10
-rw-r--r--libimagstore/src/util.rs35
5 files changed, 54 insertions, 1 deletions
diff --git a/imag-store/Cargo.toml b/imag-store/Cargo.toml
index 66648cb..13e8eba 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 656092f..08d9f5e 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 a420b5f..56c3a74 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 4391433..d245feb 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 0000000..9ff4a14
--- /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 <mail@beyermatthias.de> 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)+) => { };
+}
+