Remove .unwrap() calls, and add more information.

This commit is contained in:
2020-01-20 15:40:00 +01:00
parent fc84eee48b
commit 6532bd5a0d
9 changed files with 26 additions and 9 deletions

View File

@@ -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(

View File

@@ -42,7 +42,9 @@ pub fn health() -> HttpResponse {
fn query((parameters, state): (Json<Query>, Data<RwLock<SharedState>>)) -> 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() {

View File

@@ -18,7 +18,9 @@ fn put(path: Path<String>) -> HandlerResult {
fn get((core, state): (Path<String>, Data<RwLock<SharedState>>)) -> 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)),

View File

@@ -14,7 +14,9 @@ use super::SharedState;
fn post((parameters, state): (Json<Filters>, Data<RwLock<SharedState>>)) -> 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) {

View File

@@ -210,7 +210,7 @@ pub fn run(host: &str, port: u16, state: Data<RwLock<SharedState>>) {
// 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!"),

View File

@@ -18,7 +18,9 @@ fn put(path: Path<String>) -> HandlerResult {
fn get((path, state): (Path<String>, Data<RwLock<SharedState>>)) -> 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) => {

View File

@@ -14,7 +14,9 @@ use super::SharedState;
fn post((parameters, state): (Json<Filters>, Data<RwLock<SharedState>>)) -> 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) {

View File

@@ -22,7 +22,9 @@ fn get((path, state): (Path<(String, String)>, Data<RwLock<SharedState>>)) -> 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?

View File

@@ -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) {