Skip to content

Commit a5cd50d

Browse files
committed
fallback error
1 parent 1c71490 commit a5cd50d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/runner.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl RunResult {
304304
pub fn json_info(result: ForFileResult) -> Self {
305305
let json = match serde_json::to_string_pretty(&result) {
306306
Ok(json) => json,
307-
Err(e) => return Self::json_io_error(Error::Io(e.to_string())),
307+
Err(e) => return Self::fallback_io_error(&e.to_string()),
308308
};
309309
Self {
310310
info_messages: vec![json],
@@ -317,9 +317,9 @@ impl RunResult {
317317
Error::Io(msg) => msg,
318318
Error::ValidationFailed => "Error::ValidationFailed".to_string(),
319319
};
320-
let json = match serde_json::to_string(&serde_json::json!({"error": message})).map_err(|e| Error::Io(e.to_string())) {
320+
let json = match serde_json::to_string(&serde_json::json!({"error": message})) {
321321
Ok(json) => json,
322-
Err(e) => return Self::json_io_error(Error::Io(e.to_string())),
322+
Err(e) => return Self::fallback_io_error(&format!("JSON serialization failed: {}", e)),
323323
};
324324
Self {
325325
io_errors: vec![json],
@@ -331,13 +331,20 @@ impl RunResult {
331331
let json_obj = serde_json::json!({"validation_errors": validation_errors});
332332
let json = match serde_json::to_string_pretty(&json_obj) {
333333
Ok(json) => json,
334-
Err(e) => return Self::json_io_error(Error::Io(e.to_string())),
334+
Err(e) => return Self::fallback_io_error(&format!("JSON serialization failed: {}", e)),
335335
};
336336
Self {
337337
validation_errors: vec![json],
338338
..Default::default()
339339
}
340340
}
341+
342+
fn fallback_io_error(message: &str) -> Self {
343+
Self {
344+
io_errors: vec![format!("{{\"error\": \"{}\"}}", message.replace('"', "\\\""))],
345+
..Default::default()
346+
}
347+
}
341348
}
342349

343350
#[cfg(test)]

0 commit comments

Comments
 (0)