Print init errors

This commit is contained in:
Andras Schmelczer 2025-03-29 12:25:24 +00:00
parent b3e98d32b6
commit 81c4cc991c
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 20 additions and 7 deletions

View file

@ -43,6 +43,25 @@ impl SyncServerError {
}
}
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct SerializedError {
pub message: String,
pub causes: Vec<String>,
}
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<String>,
}
impl From<&anyhow::Error> for SerializedError {
fn from(error: &anyhow::Error) -> SerializedError {
let mut causes = vec![];

View file

@ -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
}
}