diff --git a/src/error.rs b/src/error.rs index 417ddfc..5c0d3a8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -9,6 +9,10 @@ impl Error { fn kind(&self) -> Option<&UploadError> { self.inner.downcast_ref() } + + pub(crate) fn root_cause(&self) -> &(dyn std::error::Error + 'static) { + self.inner.root_cause() + } } impl std::fmt::Debug for Error { @@ -188,20 +192,11 @@ impl ResponseError for Error { } fn error_response(&self) -> HttpResponse { - if let Some(kind) = self.kind() { - HttpResponse::build(self.status_code()) - .content_type("application/json") - .body( - serde_json::to_string(&serde_json::json!({ "msg": kind.to_string() })) - .unwrap_or_else(|_| r#"{"msg":"Request failed"}"#.to_string()), - ) - } else { - HttpResponse::build(self.status_code()) - .content_type("application/json") - .body( - serde_json::to_string(&serde_json::json!({ "msg": "Unknown error" })) - .unwrap_or_else(|_| r#"{"msg":"Request failed"}"#.to_string()), - ) - } + HttpResponse::build(self.status_code()) + .content_type("application/json") + .body( + serde_json::to_string(&serde_json::json!({ "msg": self.root_cause().to_string() })) + .unwrap_or_else(|_| r#"{"msg":"Request failed"}"#.to_string()), + ) } } diff --git a/src/process.rs b/src/process.rs index 3246b86..2fbd08e 100644 --- a/src/process.rs +++ b/src/process.rs @@ -44,9 +44,12 @@ pin_project_lite::pin_project! { #[derive(Debug, thiserror::Error)] pub(crate) enum ProcessError { - #[error("Required command {0} not found")] + #[error("Required command {0} not found, make sure it exists in pict-rs' $PATH")] NotFound(String), + #[error("Cannot run command {0} due to invalid permissions on binary, make sure the pict-rs user has permission to run it")] + PermissionDenied(String), + #[error("Reached process spawn limit")] LimitReached, @@ -66,6 +69,9 @@ impl Process { Ok(this) => Ok(this), Err(e) => match e.kind() { std::io::ErrorKind::NotFound => Err(ProcessError::NotFound(command.to_string())), + std::io::ErrorKind::PermissionDenied => { + Err(ProcessError::PermissionDenied(command.to_string())) + } std::io::ErrorKind::WouldBlock => Err(ProcessError::LimitReached), _ => Err(ProcessError::Other(e)), }, diff --git a/src/queue/process.rs b/src/queue/process.rs index ea46fd3..0c055e1 100644 --- a/src/queue/process.rs +++ b/src/queue/process.rs @@ -105,7 +105,7 @@ where tracing::warn!("Failed to ingest\n{}\n{}", format!("{e}"), format!("{e:?}")); UploadResult::Failure { - message: e.to_string(), + message: e.root_cause().to_string(), } } };