improve error logging #33
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue