git.delta.rocks / jrsonnet / refs/commits / 7c1d01aa94c2

difftreelog

feat print errors to stderr, exit 1 on failure

Alexander Kursell2021-01-06parent: #55a12da.patch.diff
in: master

1 file changed

modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
4343
44fn main() {44fn main() {
45 let opts: Opts = Opts::parse();45 let opts: Opts = Opts::parse();
46 let success;
46 if let Some(size) = opts.debug.os_stack {47 if let Some(size) = opts.debug.os_stack {
47 std::thread::Builder::new()48 success = std::thread::Builder::new()
48 .stack_size(size * 1024 * 1024)49 .stack_size(size * 1024 * 1024)
49 .spawn(|| main_catch(opts))50 .spawn(|| main_catch(opts))
50 .expect("new thread spawned")51 .expect("new thread spawned")
51 .join()52 .join()
52 .expect("thread finished successfully");53 .expect("thread finished successfully");
53 } else {54 } else {
54 main_catch(opts)55 success = main_catch(opts)
55 }56 }
57 if !success {
58 std::process::exit(1);
59 }
56}60}
5761
58#[derive(thiserror::Error, Debug)]62#[derive(thiserror::Error, Debug)]
71 }75 }
72}76}
7377
74fn main_catch(opts: Opts) {78fn main_catch(opts: Opts) -> bool {
75 let state = EvaluationState::default();79 let state = EvaluationState::default();
76 if let Err(e) = main_real(&state, opts) {80 if let Err(e) = main_real(&state, opts) {
77 if let Error::Evaluation(e) = e {81 if let Error::Evaluation(e) = e {
78 println!("{}", state.stringify_err(&e));82 eprintln!("{}", state.stringify_err(&e));
79 } else {83 } else {
80 println!("{}", e);84 eprintln!("{}", e);
81 }85 }
86 return false;
82 }87 }
88 true
83}89}
8490
85fn main_real(state: &EvaluationState, opts: Opts) -> Result<(), Error> {91fn main_real(state: &EvaluationState, opts: Opts) -> Result<(), Error> {