From 62b5aded86b2c69da4d5d36af5d554229a3b3c8b Mon Sep 17 00:00:00 2001 From: Astrid Date: Mon, 12 Feb 2024 13:55:46 +0100 Subject: [PATCH] Print inner error better --- src/main.rs | 8 ++------ src/migrate.rs | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0deb546..2af7c5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ mod process; mod pull; mod store; +use std::error::Error; use crate::db::{ImageMeta, Stats}; use crate::pull::Puller; use crate::store::Storer; @@ -233,12 +234,7 @@ impl IntoResponse for PKAvatarError { }; // print inner error if otherwise hidden - match self { - PKAvatarError::InternalError(ref e) => error!("error: {}", e), - PKAvatarError::NetworkError(ref e) => error!("error: {}", e), - PKAvatarError::ImageFormatError(ref e) => error!("error: {}", e), - _ => error!("error: {}", &self), - } + error!("error: {}", self.source().unwrap_or(&self)); ( status_code, diff --git a/src/migrate.rs b/src/migrate.rs index 20d794b..d96d7dd 100644 --- a/src/migrate.rs +++ b/src/migrate.rs @@ -1,3 +1,4 @@ +use std::error::Error; use crate::db::{ImageMeta, ImageQueueEntry}; use crate::pull::parse_url; use crate::{db, process, AppState, PKAvatarError}; @@ -69,7 +70,6 @@ pub async fn handle_item(state: &AppState) -> Result<(), PKAvatarError> { | PKAvatarError::UnknownImageFormat | PKAvatarError::UnsupportedImageFormat(_) | PKAvatarError::ImageFileSizeTooLarge(_, _) - | PKAvatarError::ImageFileSizeTooLarge(_, _) | PKAvatarError::InvalidCdnUrl | PKAvatarError::BadCdnResponse(StatusCode::NOT_FOUND | StatusCode::FORBIDDEN)), ) => { @@ -92,7 +92,7 @@ pub async fn worker(worker_id: u32, state: Arc) { match handle_item(&state).await { Ok(()) => {} Err(e) => { - error!("error in migrate worker {}: {}", worker_id, e); + error!("error in migrate worker {}: {}", worker_id, e.source().unwrap_or(&e)); tokio::time::sleep(Duration::from_secs(5)).await; } }