feat(users/Profpatsch): add die_* helpers for semantic exit errors
There is this semantic exit code schema championed by execline and
skaware tooling, and we refined and documented it a bit in lorri
d1d673d420/src/ops/mod.rs (L24-L35)
in the past.
This just transcribes the error messages into simple helper functions.
Applies the functions to the places where we would panic or die
`sys::exit()` instead.
Change-Id: I15ca05cd6f99a25a3378518be94110eab416354e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2475
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
parent
83634341aa
commit
492b79ec7a
5 changed files with 80 additions and 28 deletions
|
|
@ -1,4 +1,5 @@
|
|||
extern crate nom;
|
||||
extern crate exec_helpers;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::io::{Write, Read};
|
||||
|
|
@ -116,15 +117,15 @@ pub fn text(s: String) -> T {
|
|||
T::Text(s)
|
||||
}
|
||||
|
||||
pub fn t_from_stdin_or_panic(prog_name: &str) -> T {
|
||||
pub fn t_from_stdin_or_die_user_error(prog_name: &str) -> T {
|
||||
let mut buf = vec![];
|
||||
std::io::stdin().lock().read_to_end(&mut buf);
|
||||
match parse::t_t(&buf) {
|
||||
Ok((rest, t)) => match rest {
|
||||
b"" => t,
|
||||
_ => panic!("{}: stdin contained some soup after netencode value: {:?}", prog_name, rest)
|
||||
_ => exec_helpers::die_user_error(prog_name, format!("stdin contained some soup after netencode value: {:?}", rest))
|
||||
},
|
||||
Err(err) => panic!("{}: unable to parse netencode from stdin: {:?}", prog_name, err)
|
||||
Err(err) => exec_helpers::die_user_error(prog_name, format!("unable to parse netencode from stdin: {:?}", err))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue