From e4c21b11069297d289f25834cfc3c001a4604b5f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 2 Nov 2018 02:59:56 +0100 Subject: run_action(): Return `Result` Instead of handling the error in this function, pass it up to the caller. This will allow the error message to be printed, as we've only allowed 'stderrlog' to print log messages in the `ffi` module. --- src/map.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/map.rs b/src/map.rs index 5741245..86d6773 100644 --- a/src/map.rs +++ b/src/map.rs @@ -3,6 +3,7 @@ use std::ffi::OsString; use std::process::Command; use {Action, HeadphoneButton, MapAction, MapKind}; +use errors::*; use ffi::State; #[repr(C)] @@ -54,7 +55,7 @@ pub fn run_key_action<'a>( } } -fn run_action(map_action: &MapAction) { +fn run_action(map_action: &MapAction) -> Result<()> { match map_action.kind { MapKind::Map => { if let Action::Map(action) = &map_action.action { @@ -70,17 +71,15 @@ fn run_action(map_action: &MapAction) { None => OsString::from("/bin/sh"), }; - match Command::new(shell) + return Command::new(shell) .arg("-c") .arg(action) - .spawn() { - Ok(_) => (), - Err(e) => error!( - "Command failed to start: `{}'", - e - ), - } + .spawn() + .map(|_| ()) + .chain_err(|| "command failed to start"); } }, - } + }; + + Ok(()) } -- cgit v1.2.3