fix(robot): propagate JSON serialization errors instead of silent failure
Three robot-mode print functions used `serde_json::to_string().unwrap_or_default()` which silently outputs an empty string on failure (exit 0, no error). This diverged from the codebase standard in handlers.rs which uses `?` propagation. Changed to return Result<()> with proper LoreError::Other mapping: - explain.rs: print_explain_json() - file_history.rs: print_file_history_json() - trace.rs: print_trace_json() Updated callers in handlers.rs and explain.rs to propagate with `?`. While serde_json::to_string on a json!() Value is unlikely to fail in practice (only non-finite floats trigger it), the unwrap_or_default pattern violates the robot mode contract: callers expect either valid JSON on stdout or a structured error on stderr with a non-zero exit code, never empty output with exit 0.
This commit is contained in:
@@ -1328,7 +1328,7 @@ fn handle_file_history(
|
||||
|
||||
if robot_mode {
|
||||
let elapsed_ms = start.elapsed().as_millis() as u64;
|
||||
print_file_history_json(&result, elapsed_ms);
|
||||
print_file_history_json(&result, elapsed_ms)?;
|
||||
} else {
|
||||
print_file_history(&result);
|
||||
}
|
||||
@@ -1384,7 +1384,7 @@ fn handle_trace(
|
||||
|
||||
if robot_mode {
|
||||
let elapsed_ms = start.elapsed().as_millis() as u64;
|
||||
print_trace_json(&result, elapsed_ms, line_requested);
|
||||
print_trace_json(&result, elapsed_ms, line_requested)?;
|
||||
} else {
|
||||
print_trace(&result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user