Skip to content

Commit

Permalink
Print inner error better
Browse files Browse the repository at this point in the history
  • Loading branch information
xSke committed Feb 12, 2024
1 parent cae4ed1 commit 62b5ade
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::error::Error;
use crate::db::{ImageMeta, ImageQueueEntry};
use crate::pull::parse_url;
use crate::{db, process, AppState, PKAvatarError};
Expand Down Expand Up @@ -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)),
) => {
Expand All @@ -92,7 +92,7 @@ pub async fn worker(worker_id: u32, state: Arc<AppState>) {
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;
}
}
Expand Down

0 comments on commit 62b5ade

Please sign in to comment.