improve error logging #33

Open
anton wants to merge 1 commits from anton/error-logging into main
2 changed files with 21 additions and 7 deletions
Showing only changes of commit 661f0f04e3 - Show all commits

View File

@ -141,11 +141,19 @@ pub trait Module {
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()) {
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())