Print init errors
This commit is contained in:
parent
b3e98d32b6
commit
81c4cc991c
2 changed files with 20 additions and 7 deletions
|
|
@ -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 {
|
impl IntoResponse for SyncServerError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
let body = Json(self.serialize());
|
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 {
|
impl From<&anyhow::Error> for SerializedError {
|
||||||
fn from(error: &anyhow::Error) -> SerializedError {
|
fn from(error: &anyhow::Error) -> SerializedError {
|
||||||
let mut causes = vec![];
|
let mut causes = vec![];
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ async fn main() -> ExitCode {
|
||||||
match result {
|
match result {
|
||||||
Ok(()) => ExitCode::SUCCESS,
|
Ok(()) => ExitCode::SUCCESS,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to set up logging: {e}");
|
eprintln!("{}", e.serialize().to_string());
|
||||||
ExitCode::FAILURE
|
ExitCode::FAILURE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue