diff --git a/src/main.rs b/src/main.rs index e035410..12e80ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,9 +100,12 @@ fn main() { let db; // Load a Database: { + // Load all the index contained in the folder, and fail if anyone of + // those is corrupted / incompatible. info_time!("Loading database index"); - db = DataBase::load(&datasets).unwrap(); + db = DataBase::load(&datasets) + .unwrap_or_else(|e| panic!("Error while loading indices: {}", e)); } rest_api::run( diff --git a/src/rest_api/actions.rs b/src/rest_api/actions.rs index ff51cc5..a10de2e 100644 --- a/src/rest_api/actions.rs +++ b/src/rest_api/actions.rs @@ -42,7 +42,9 @@ pub fn health() -> HttpResponse { fn query((parameters, state): (Json, Data>)) -> HandlerResult { trace!("POST '{:?}'", parameters); - let context = state.read().unwrap(); + let context = state + .read() + .unwrap_or_else(|e| panic!("Can't acquire read lock of the database: {}", e)); let query = parameters.query(); if query.is_empty() { diff --git a/src/rest_api/core.rs b/src/rest_api/core.rs index 62bdc16..d15c259 100644 --- a/src/rest_api/core.rs +++ b/src/rest_api/core.rs @@ -18,7 +18,9 @@ fn put(path: Path) -> HandlerResult { fn get((core, state): (Path, Data>)) -> HandlerResult { trace!("GET '{:?}'", core); let core = core.to_string(); - let context = state.read().unwrap(); + let context = state + .read() + .unwrap_or_else(|e| panic!("Can't acquire read lock of the database: {}", e)); match context.db().core(&core) { Ok(core) => ok_200(&Core::from(core)), diff --git a/src/rest_api/cores.rs b/src/rest_api/cores.rs index e9b9476..87666c0 100644 --- a/src/rest_api/cores.rs +++ b/src/rest_api/cores.rs @@ -14,7 +14,9 @@ use super::SharedState; fn post((parameters, state): (Json, Data>)) -> HandlerResult { trace!("POST '{:?}'", parameters); - let context = state.read().unwrap(); + let context = state + .read() + .unwrap_or_else(|e| panic!("Can't acquire read lock of the database: {}", e)); let db = context.db(); match parameters.space(db) { diff --git a/src/rest_api/mod.rs b/src/rest_api/mod.rs index c1740a7..e5116cb 100644 --- a/src/rest_api/mod.rs +++ b/src/rest_api/mod.rs @@ -210,7 +210,7 @@ pub fn run(host: &str, port: u16, state: Data>) { // Create & run the server. match HttpServer::new(move || get_app!(state)) .bind(format!("{}:{}", host, port)) - .unwrap() + .unwrap_or_else(|e| panic!("Failed to bind to `{}:{}`: {}", host, port, e)) .run() { Ok(_) => info!("Server Stopped!"), diff --git a/src/rest_api/space.rs b/src/rest_api/space.rs index eb78868..9aaae7a 100644 --- a/src/rest_api/space.rs +++ b/src/rest_api/space.rs @@ -18,7 +18,9 @@ fn put(path: Path) -> HandlerResult { fn get((path, state): (Path, Data>)) -> HandlerResult { trace!("GET '{:?}'", path); let name = path.to_string(); - let context = state.read().unwrap(); + let context = state + .read() + .unwrap_or_else(|e| panic!("Can't acquire read lock of the database: {}", e)); match context.db().space(&name) { Ok(space) => { diff --git a/src/rest_api/spaces.rs b/src/rest_api/spaces.rs index e097c1f..3fc20e6 100644 --- a/src/rest_api/spaces.rs +++ b/src/rest_api/spaces.rs @@ -14,7 +14,9 @@ use super::SharedState; fn post((parameters, state): (Json, Data>)) -> HandlerResult { trace!("POST '{:?}'", parameters); - let context = state.read().unwrap(); + let context = state + .read() + .unwrap_or_else(|e| panic!("Can't acquire read lock of the database: {}", e)); let db = context.db(); match parameters.space(db) { diff --git a/src/rest_api/spatial_object.rs b/src/rest_api/spatial_object.rs index c616c34..2ab7225 100644 --- a/src/rest_api/spatial_object.rs +++ b/src/rest_api/spatial_object.rs @@ -22,7 +22,9 @@ fn get((path, state): (Path<(String, String)>, Data>)) -> Ha let (core, id) = path.into_inner(); let core = core; let id = id; - let context = state.read().unwrap(); + let context = state + .read() + .unwrap_or_else(|e| panic!("Can't acquire read lock of the database: {}", e)); let db = context.db(); // FIXME: Should we allow setting the resolution/threshold_volume? diff --git a/src/rest_api/spatial_objects.rs b/src/rest_api/spatial_objects.rs index 2433629..1f7734a 100644 --- a/src/rest_api/spatial_objects.rs +++ b/src/rest_api/spatial_objects.rs @@ -21,7 +21,9 @@ fn post( ) -> HandlerResult { trace!("POST '{:?}', {:?}", parameters, core_id); let core_id = core_id.to_string(); - let context = state.read().unwrap(); + let context = state + .read() + .unwrap_or_else(|e| panic!("Can't acquire read lock of the database: {}", e)); let db = context.db(); match db.core(&core_id) {