fix: add proper targets to db logging, panic in debug mode
parent
6394a70030
commit
3292a5b346
|
@ -30,6 +30,7 @@ use diesel::r2d2::{self, ConnectionManager};
|
|||
use diesel::result::{DatabaseErrorKind, Error};
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use hierarchies::initialize_hier;
|
||||
use shadow_rs::is_debug;
|
||||
use std::convert::TryFrom;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
@ -73,11 +74,16 @@ impl diesel::r2d2::CustomizeConnection<SqliteConnection, diesel::r2d2::Error>
|
|||
type DbPool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LoggingHandler {}
|
||||
pub struct LoggingHandler {
|
||||
pub target: &'static str,
|
||||
}
|
||||
|
||||
impl diesel::r2d2::HandleError<diesel::r2d2::Error> for LoggingHandler {
|
||||
fn handle_error(&self, error: diesel::r2d2::Error) {
|
||||
error!("{}", error);
|
||||
error!(target = self.target, "{}", error);
|
||||
if is_debug() {
|
||||
panic!("This should not happen! {}", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +127,9 @@ impl UpEndDatabase {
|
|||
enable_foreign_keys: true,
|
||||
busy_timeout: Some(Duration::from_secs(30)),
|
||||
}))
|
||||
.error_handler(Box::new(LoggingHandler {}))
|
||||
.error_handler(Box::new(LoggingHandler {
|
||||
target: "upend::db::main",
|
||||
}))
|
||||
.build(manager)?;
|
||||
trace!("Pool created.");
|
||||
|
||||
|
|
|
@ -122,7 +122,9 @@ impl FsStore {
|
|||
|
||||
let pool = r2d2::Pool::builder()
|
||||
.connection_customizer(Box::new(ConnectionOptions {}))
|
||||
.error_handler(Box::new(LoggingHandler {}))
|
||||
.error_handler(Box::new(LoggingHandler {
|
||||
target: "upend::db::fs",
|
||||
}))
|
||||
.build(manager)?;
|
||||
|
||||
let lock = Arc::new(RwLock::new(()));
|
||||
|
|
Loading…
Reference in New Issue