improve error logging

This commit is contained in:
Anton Livaja 2025-02-11 12:32:45 -05:00
parent dcb9c50d29
commit 661f0f04e3
Signed by: anton
GPG Key ID: 44A86CFF1FDF0E85
2 changed files with 21 additions and 7 deletions

View File

@ -141,10 +141,18 @@ pub trait Module {
break; break;
} }
} }
// TODO: error handling
let request: Self::Request = serde_json::from_value(value).expect("good value"); match serde_json::from_value::<Self::Request>(value.clone()) {
let response = Self::handle_request(request)?; Ok(request) => {
println!("{}", serde_json::to_string(&response).unwrap()); let response = Self::handle_request(request)?;
println!("{}", serde_json::to_string(&response).unwrap());
}
Err(e) => {
eprintln!("Failed to parse request: {e}");
eprintln!("Offending JSON value: {value:?}");
continue;
}
}
} }
Ok(()) Ok(())
} }

View File

@ -174,12 +174,18 @@ pub fn do_cli_thing() {
.clone() .clone()
.unwrap_or_else(|| format!("icepick-{module_name}")); .unwrap_or_else(|| format!("icepick-{module_name}"));
let (command, args) = get_command(&bin); let (command, args) = get_command(&bin);
let mut child = Command::new(command) let mut child = match Command::new(&command)
.args(args) .args(&args)
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.spawn() .spawn()
.unwrap(); {
Ok(child) => child,
Err(e) => {
eprintln!("Failed to spawn command `{}`: {}", command, e);
return;
}
};
let mut input = child.stdin.take().unwrap(); let mut input = child.stdin.take().unwrap();
input input
.write_all("{\"operation\": \"help\"}\n".as_bytes()) .write_all("{\"operation\": \"help\"}\n".as_bytes())