From 81c4cc991c5d817857b02a10d23ddddd071ba314 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 29 Mar 2025 12:25:24 +0000 Subject: [PATCH] Print init errors --- backend/sync_server/src/errors.rs | 25 +++++++++++++++++++------ backend/sync_server/src/main.rs | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/backend/sync_server/src/errors.rs b/backend/sync_server/src/errors.rs index 3153810..c5b46c2 100644 --- a/backend/sync_server/src/errors.rs +++ b/backend/sync_server/src/errors.rs @@ -43,6 +43,25 @@ impl SyncServerError { } } +#[derive(Debug, Clone, Serialize, JsonSchema)] +pub struct SerializedError { + pub message: String, + pub causes: Vec, +} + +impl ToString for SerializedError { + fn to_string(&self) -> String { + let mut result = self.message.clone(); + if !self.causes.is_empty() { + result.push_str("\nCauses:\n"); + for cause in &self.causes { + result.push_str(&format!("- {}\n", cause)); + } + } + result + } +} + impl IntoResponse for SyncServerError { fn into_response(self) -> Response { let body = Json(self.serialize()); @@ -59,12 +78,6 @@ impl IntoResponse for SyncServerError { } } -#[derive(Debug, Clone, Serialize, JsonSchema)] -pub struct SerializedError { - pub message: String, - pub causes: Vec, -} - impl From<&anyhow::Error> for SerializedError { fn from(error: &anyhow::Error) -> SerializedError { let mut causes = vec![]; diff --git a/backend/sync_server/src/main.rs b/backend/sync_server/src/main.rs index b3989b0..9b2686f 100644 --- a/backend/sync_server/src/main.rs +++ b/backend/sync_server/src/main.rs @@ -29,7 +29,7 @@ async fn main() -> ExitCode { match result { Ok(()) => ExitCode::SUCCESS, Err(e) => { - eprintln!("Failed to set up logging: {e}"); + eprintln!("{}", e.serialize().to_string()); ExitCode::FAILURE } }