From 22ae479bd779fa6430124bab0ec79c24668c7061 Mon Sep 17 00:00:00 2001 From: trisua Date: Wed, 28 May 2025 13:41:19 -0400 Subject: [PATCH] add: provide more information on psql and redis connection errors --- README.md | 10 ++++++++++ .../src/routes/api/v1/auth/connections/last_fm.rs | 13 +++++++------ crates/core/src/cache/redis.rs | 7 +++++-- crates/core/src/database/drivers/postgres.rs | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0d42c38..865ebae 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,16 @@ Tetratto is very simple once you get the hang of it! At the top of the page (or All Tetratto instances support reports for communities and posts through the UI. You can just find the ellipsis icon on either and then press "Report" to file a report! +## Debugging + +All panics should be reported as a bug report (or on tetratto.com). Panics which cannot be avoided will have an error tag attached to their error message, so you can easily search through your service logs to understand more. All error tags will begin with `ERROR_TETRATTO_`, and will have a more detailed tag suffix. + +All current panic tags are listed below: + +- `ERROR_TETRATTO_PSQL_CON` - errors in connection to the postgres database +- `ERROR_TETRATTO_REDIS_CON` - an error in creating the redis connection pool +- `ERROR_TETRATTO_REDIS_CON_ACQUIRE` - an error in acquiring a redis connection + # Updating When bumping versions, you _might_ need to run a few SQL scripts in order to get your database up to what the next commit expects. It is recommended to only update from GitHub release, which will list the SQL scripts you need to run to migrate your database. diff --git a/crates/app/src/routes/api/v1/auth/connections/last_fm.rs b/crates/app/src/routes/api/v1/auth/connections/last_fm.rs index 7f006c8..0519d0a 100644 --- a/crates/app/src/routes/api/v1/auth/connections/last_fm.rs +++ b/crates/app/src/routes/api/v1/auth/connections/last_fm.rs @@ -119,12 +119,13 @@ pub async fn proxy_request( } // ... - let res = reqwest::get(format!("https://ws.audioscrobbler.com/2.0/{out}")) - .await - .unwrap() - .text() - .await - .unwrap(); + let res = match reqwest::get(format!("https://ws.audioscrobbler.com/2.0/{out}")).await { + Ok(c) => c, + Err(e) => return Json(Error::MiscError(e.to_string()).into()), + } + .text() + .await + .unwrap(); Json(ApiReturn { ok: true, diff --git a/crates/core/src/cache/redis.rs b/crates/core/src/cache/redis.rs index ce04c75..c7107bd 100644 --- a/crates/core/src/cache/redis.rs +++ b/crates/core/src/cache/redis.rs @@ -16,12 +16,15 @@ impl Cache for RedisCache { async fn new() -> Self { Self { - client: redis::Client::open("redis://127.0.0.1:6379").unwrap(), + client: redis::Client::open("redis://127.0.0.1:6379") + .expect("ERROR_TETRATTO_REDIS_CON"), } } async fn get_con(&self) -> Self::Client { - self.client.get_connection().unwrap() + self.client + .get_connection() + .expect("ERROR_TETRATTO_PSQL_CON_ACQUIRE") } async fn get(&self, id: Self::Item) -> Option { diff --git a/crates/core/src/database/drivers/postgres.rs b/crates/core/src/database/drivers/postgres.rs index 7e739c1..3b48211 100644 --- a/crates/core/src/database/drivers/postgres.rs +++ b/crates/core/src/database/drivers/postgres.rs @@ -30,7 +30,7 @@ pub struct DataManager( impl DataManager { /// Obtain a connection to the staging database. pub(crate) async fn connect(&self) -> Result { - Ok(self.3.get().await.unwrap()) + Ok(self.3.get().await.expect("ERROR_TETRATTO_PSQL_CON")) } /// Create a new [`DataManager`] (and init database).