More accurate panic message on mutex poison

This commit is contained in:
Sofía Aritz 2023-04-01 22:37:21 +02:00
parent 915dd13e74
commit e7d09fb314
3 changed files with 8 additions and 3 deletions

2
Cargo.lock generated
View file

@ -1438,7 +1438,7 @@ dependencies = [
[[package]]
name = "simple-analytics"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"anyhow",
"async-std",

View file

@ -1,6 +1,6 @@
[package]
name = "simple-analytics"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
[dependencies]

View file

@ -13,7 +13,12 @@ pub async fn submit_event(mut req: Request<State>) -> 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)",