From e7d09fb31402c9147f2ae2e167727df7c9e9ea97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sof=C3=ADa=20Aritz?= Date: Sat, 1 Apr 2023 22:37:21 +0200 Subject: [PATCH] More accurate panic message on mutex poison --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/submit.rs | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cfff967..ea637bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1438,7 +1438,7 @@ dependencies = [ [[package]] name = "simple-analytics" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "async-std", diff --git a/Cargo.toml b/Cargo.toml index 581ff8e..fc3add9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "simple-analytics" -version = "0.1.0" +version = "0.1.1" edition = "2021" [dependencies] diff --git a/src/submit.rs b/src/submit.rs index f0d7363..07076aa 100644 --- a/src/submit.rs +++ b/src/submit.rs @@ -13,7 +13,12 @@ pub async fn submit_event(mut req: Request) -> tide::Result { { let state = req.state().clone(); - let connection = state.0.lock().expect("failed to get read lock"); + let connection = if let Ok(v) = state.0.lock() { + v + } else { + error!("database mutex is poisoned. Restarting is probably required!"); + panic!("database mutex is poisoned"); + }; if let Err(err) = connection.execute( "INSERT INTO analytics (id, event_name, data) VALUES (?1, ?2, ?3)",