log errors when db queries fails
This commit is contained in:
parent
295efdba55
commit
5c4086bf8e
@ -41,21 +41,33 @@ pub trait Readable {
|
|||||||
|
|
||||||
impl Writable for DBTransaction {
|
impl Writable for DBTransaction {
|
||||||
fn write<T>(&self, key: &Key<T>, value: &T) where T: Encodable {
|
fn write<T>(&self, key: &Key<T>, value: &T) where T: Encodable {
|
||||||
self.put(&key.key(), &encode(value))
|
let result = self.put(&key.key(), &encode(value));
|
||||||
.expect("db put failed");
|
if let Err(err) = result {
|
||||||
|
panic!("db put failed, key: {:?}, err: {:?}", key.key(), err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Readable for Database {
|
impl Readable for Database {
|
||||||
fn read<T>(&self, key: &Key<T>) -> Option<T> where T: Decodable {
|
fn read<T>(&self, key: &Key<T>) -> Option<T> where T: Decodable {
|
||||||
self.get(&key.key())
|
let result = self.get(&key.key());
|
||||||
.expect("db get failed")
|
|
||||||
.map(|v| decode(&v))
|
match result {
|
||||||
|
Ok(option) => option.map(|v| decode(&v)),
|
||||||
|
Err(err) => {
|
||||||
|
panic!("db get failed, key: {:?}, err: {:?}", key.key(), err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exists<T>(&self, key: &Key<T>) -> bool {
|
fn exists<T>(&self, key: &Key<T>) -> bool {
|
||||||
self.get(&key.key())
|
let result = self.get(&key.key());
|
||||||
.expect("db get failed")
|
|
||||||
.is_some()
|
match result {
|
||||||
|
Ok(v) => v.is_some(),
|
||||||
|
Err(err) => {
|
||||||
|
panic!("db get failed, key: {:?}, err: {:?}", key.key(), err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user