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;
}
}
// TODO: error handling
let request: Self::Request = serde_json::from_value(value).expect("good value");
let response = Self::handle_request(request)?;
println!("{}", serde_json::to_string(&response).unwrap());
match serde_json::from_value::<Self::Request>(value.clone()) {
Ok(request) => {
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(())
}

View File

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