diff options
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | talpid_cli/Cargo.toml | 1 | ||||
| -rw-r--r-- | talpid_cli/src/main.rs | 26 |
3 files changed, 20 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock index 77973ad11c..4fb8fb2009 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,6 +129,7 @@ name = "talpid_cli" version = "0.0.0" dependencies = [ "clap 2.20.3 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "talpid_core 0.0.0", ] diff --git a/talpid_cli/Cargo.toml b/talpid_cli/Cargo.toml index 5abed624a4..637b1f6699 100644 --- a/talpid_cli/Cargo.toml +++ b/talpid_cli/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Linus Färnstrand <linus@mullvad.net>"] [dependencies] clap = "2.20" +error-chain = "0.8" [dependencies.talpid_core] path = "../" diff --git a/talpid_cli/src/main.rs b/talpid_cli/src/main.rs index a174d7ed37..9961466a00 100644 --- a/talpid_cli/src/main.rs +++ b/talpid_cli/src/main.rs @@ -1,18 +1,27 @@ extern crate talpid_core; #[macro_use] extern crate clap; +#[macro_use] +extern crate error_chain; use std::io::{self, Read, Write}; use std::sync::mpsc::{self, Receiver}; use std::thread; use talpid_core::process::OpenVpnCommand; -use talpid_core::process::monitor::{ChildMonitor, TransitionResult, ChildSpawner}; +use talpid_core::process::monitor::{ChildMonitor, ChildSpawner}; mod cli; use cli::Args; + +error_chain! { + links { + Monitor(talpid_core::process::monitor::Error, talpid_core::process::monitor::ErrorKind); + } +} + /// Macro for printing to stderr. Will simply do nothing if the printing fails for some reason. macro_rules! eprintln { ($($arg:tt)*) => ( @@ -41,7 +50,7 @@ fn create_openvpn_command(args: &Args) -> OpenVpnCommand { command } -fn main_loop<S>(mut monitor: ChildMonitor<S>) -> TransitionResult<()> +fn main_loop<S>(mut monitor: ChildMonitor<S>) -> Result<()> where S: ChildSpawner { loop { @@ -52,16 +61,17 @@ fn main_loop<S>(mut monitor: ChildMonitor<S>) -> TransitionResult<()> } } -fn start_monitor<S>(monitor: &mut ChildMonitor<S>) -> TransitionResult<Receiver<bool>> +fn start_monitor<S>(monitor: &mut ChildMonitor<S>) -> Result<Receiver<bool>> where S: ChildSpawner { let (tx, rx) = mpsc::channel(); let callback = move |clean| tx.send(clean).unwrap(); - monitor.start(callback).map(|(stdout, stderr)| { - stdout.map(|stream| pass_io(stream, io::stdout())); - stderr.map(|stream| pass_io(stream, io::stderr())); - rx - }) + Ok(monitor.start(callback) + .map(|(stdout, stderr)| { + stdout.map(|stream| pass_io(stream, io::stdout())); + stderr.map(|stream| pass_io(stream, io::stderr())); + rx + })?) } fn pass_io<I, O>(mut input: I, mut output: O) |
