diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-02-08 13:32:14 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-02-08 13:32:14 +0100 |
| commit | 3738df928c5b49a564e067b584c442fd66edfc01 (patch) | |
| tree | d50217fdc6db6310cc9417a445571d4017073d8f /talpid_cli/src | |
| parent | d5ed46fccd3330a46bfd92976eb86fa1ff1984f1 (diff) | |
| download | mullvadvpn-3738df928c5b49a564e067b584c442fd66edfc01.tar.xz mullvadvpn-3738df928c5b49a564e067b584c442fd66edfc01.zip | |
Print errors and backtrace in talpid_cli
Diffstat (limited to 'talpid_cli/src')
| -rw-r--r-- | talpid_cli/src/main.rs | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/talpid_cli/src/main.rs b/talpid_cli/src/main.rs index 9961466a00..4a4239f622 100644 --- a/talpid_cli/src/main.rs +++ b/talpid_cli/src/main.rs @@ -1,3 +1,6 @@ +// `error_chain!` can recurse deeply +#![recursion_limit = "1024"] + extern crate talpid_core; #[macro_use] extern crate clap; @@ -22,22 +25,25 @@ error_chain! { } } -/// Macro for printing to stderr. Will simply do nothing if the printing fails for some reason. -macro_rules! eprintln { - ($($arg:tt)*) => ( - use std::io::Write; - let _ = writeln!(&mut ::std::io::stderr(), $($arg)* ); - ) -} fn main() { - let args = cli::parse_args_or_exit(); + if let Err(ref e) = run() { + println!("error: {}", e); + for e in e.iter().skip(1) { + println!("caused by: {}", e); + } + if let Some(backtrace) = e.backtrace() { + println!("backtrace: {:?}", backtrace); + } + ::std::process::exit(1); + } +} +fn run() -> Result<()> { + let args = cli::parse_args_or_exit(); let command = create_openvpn_command(&args); let monitor = ChildMonitor::new(command); - if let Err(e) = main_loop(monitor) { - eprintln!("OpenVPN failed: {}", e); - } + main_loop(monitor) } fn create_openvpn_command(args: &Args) -> OpenVpnCommand { @@ -54,7 +60,7 @@ fn main_loop<S>(mut monitor: ChildMonitor<S>) -> Result<()> where S: ChildSpawner { loop { - let rx = start_monitor(&mut monitor)?; + let rx = start_monitor(&mut monitor).chain_err(|| "Unable to start OpenVPN")?; let clean_exit = rx.recv().unwrap(); println!("Monitored process exited. clean: {}", clean_exit); std::thread::sleep(std::time::Duration::from_millis(500)); |
