commit 67ccfc97e548203686af985b8115d110d14bf30f
parent eb044e6cad119242ef3a06a5f01a75647e970184
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 8 Jun 2025 23:11:24 +0200
more logging, harsher error handling
Diffstat:
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/main.rs b/src/main.rs
@@ -18,7 +18,7 @@
use std::collections::HashMap;
use std::env;
use std::fs;
-use std::io::{self, BufRead, BufReader};
+use std::io::{self, Write, BufRead, BufReader};
use serde_json::{Value, Map};
// Finite State Machine for efficient string matching
@@ -258,20 +258,24 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for line in reader.lines() {
let line = line?;
if line.trim().is_empty() {
- continue;
+ eprintln!("ERROR: empty input line");
+ std::process::exit(1);
}
match serde_json::from_str::<Value>(&line) {
Ok(Value::Object(obj)) => {
+ eprintln!("INFO: robocop received input: {}", line);
let (quality, confidence, ssid) = engine.find_best_match(&obj);
println!("{:.6} {:.6} {}", quality, confidence, ssid);
+ // Not 100% clear if flush is needed here, but safer.
+ io::stdout().flush().unwrap();
}
Ok(_) => {
- eprintln!("Warning: Skipping non-object JSON: {}", line);
+ eprintln!("ERROR: non-object JSON received: {}", line);
std::process::exit(1);
}
Err(e) => {
- eprintln!("Warning: Failed to parse JSON: {} - {}", line, e);
+ eprintln!("ERROR: Failed to parse JSON: {} - {}", line, e);
std::process::exit(1);
}
}