Remove failure entirely
4 files changed, 21 insertions(+), 45 deletions(-)

M Cargo.lock
M Cargo.toml
M src/bin/brightd.rs
M src/dbus.rs
M Cargo.lock +0 -2
@@ 111,8 111,6 @@ dependencies = [
  "clap",
  "ctrlc",
  "dbus",
- "failure",
- "failure_derive",
  "log",
  "simplelog",
  "systemd",

          
M Cargo.toml +0 -2
@@ 14,8 14,6 @@ backtrace = "0.3.53"
 clap = "2.31"
 ctrlc = {version = "3.1.2", features = ["termination"]}
 dbus = "0.6.4"
-failure = "0.1.5"
-failure_derive = "0.1.5"
 log = "0.4.1"
 simplelog = "0.5.2"
 systemd = "0.4.0"

          
M src/bin/brightd.rs +12 -26
@@ 3,25 3,11 @@ use std::os::unix::net::UnixStream;
 use std::rc::Rc;
 use std::sync::mpsc;
 
-use failure::ResultExt;
+use anyhow::{Context, Result};
 use log::{debug, error, info};
 
-fn main() {
+fn main() -> Result<()> {
     let argv: Vec<String> = std::env::args().collect();
-    run(argv).unwrap_or_else(|err| {
-        log_error(err);
-        std::process::exit(1);
-    });
-}
-
-fn log_error(err: failure::Error) {
-    error!("{}", err);
-    for cause in err.iter_causes() {
-        error!("{}", cause)
-    }
-}
-
-fn run(argv: Vec<String>) -> Result<(), failure::Error> {
     let cfg = AppConfig::new(&argv)?;
     let cfg2 = cfg.clone();
     let (busname_tx, busname_rx) = mpsc::channel::<String>();

          
@@ 36,15 22,16 @@ fn run(argv: Vec<String>) -> Result<(), 
     }
     let exited = pond.wait();
     if exited.result.is_err() {
-        return Err(failure::err_msg(format!(
+        return Err(anyhow::anyhow!(
             "Thread \"{}\" failed: {:?}",
-            exited.name, exited.result
-        )));
+            exited.name,
+            exited.result
+        ));
     }
     Ok(())
 }
 
-fn run_acpi_listener(cfg: AppConfig, busname_rx: mpsc::Receiver<String>) -> failure::Fallible<()> {
+fn run_acpi_listener(cfg: AppConfig, busname_rx: mpsc::Receiver<String>) -> Result<()> {
     let peer = busname_rx
         .recv()
         .context("Peer D-Bus busname receiver died")?;

          
@@ 69,13 56,13 @@ fn run_acpi_listener(cfg: AppConfig, bus
     Ok(())
 }
 
-fn run_dbus_svc(cfg: AppConfig, busname_tx: mpsc::Sender<String>) -> Result<(), failure::Error> {
+fn run_dbus_svc(cfg: AppConfig, busname_tx: mpsc::Sender<String>) -> Result<()> {
     let devices = bright::create_devices(Vec::new())?;
     let mut dbus_svc = match bright::dbus::DBusService::new(cfg.bustype, Rc::new(devices)) {
         Ok(svc) => svc,
         Err(err) => {
             error!("{}", err);
-            return Err(failure::err_msg("Failed to create dbus service"));
+            return Err(anyhow::anyhow!("Failed to create dbus service"));
         }
     };
     busname_tx.send(dbus_svc.unique_name()).unwrap();

          
@@ 132,7 119,7 @@ fn setup_ctrlc(bustype: dbus::BusType, p
 //     }
 // }
 
-// Application configuration
+/// Application configuration
 #[derive(Debug, Clone)]
 struct AppConfig {
     bustype: dbus::BusType,

          
@@ 143,7 130,7 @@ struct AppConfig {
 }
 
 impl AppConfig {
-    fn new(argv: &[String]) -> Result<AppConfig, failure::Error> {
+    fn new(argv: &[String]) -> Result<AppConfig> {
         let matches = bright::cli::brightd_app().get_matches_from(argv);
         let level = match matches.value_of("loglevel") {
             Some("debug") => log::LevelFilter::Debug,

          
@@ 154,8 141,7 @@ impl AppConfig {
             None => panic!("No loglevel"),
         };
         if matches.is_present("systemd") {
-            log::set_logger(&LOGGER)
-                .map_err(|e| failure::err_msg(format!("Failed to intialise logging: {:?}", e)))?;
+            log::set_logger(&LOGGER).context("Failed to intialise logging")?;
             log::set_max_level(level);
         } else {
             simplelog::TermLogger::init(level, simplelog::Config::default())?;

          
M src/dbus.rs +9 -15
@@ 34,6 34,7 @@ use std::fmt;
 use std::rc::Rc;
 use std::sync::Arc;
 
+use anyhow::Result;
 use dbus::{self, stdintf::org_freedesktop_dbus::Properties};
 use log::{debug, error, info};
 

          
@@ 100,10 101,7 @@ impl DBusService {
         Ok(svc)
     }
 
-    pub fn incoming(
-        &mut self,
-        timeout_ms: u32,
-    ) -> Result<dbus::ConnMsgs<&dbus::Connection>, failure::Error> {
+    pub fn incoming(&mut self, timeout_ms: u32) -> Result<dbus::ConnMsgs<&dbus::Connection>> {
         for (name, val) in self.state_rx.try_iter() {
             self.states.insert(name, val);
         }

          
@@ 126,7 124,7 @@ impl DBusService {
                     device.get()?,
                     curr_state,
                 )
-                .map_err(|_err| failure::err_msg("WTF Rust error handling"))?;
+                .map_err(|_err| anyhow::anyhow!("WTF Rust error handling"))?;
             }
         }
         Ok(self.connection.incoming(timeout_ms))

          
@@ 141,10 139,7 @@ impl DBusService {
     /// should be called, in which case the timeout will be ignored and
     /// the function will return early.  Otherwise
     /// Ok(SvcStatus::Running) is returned.
-    pub fn handle_msgs(
-        &mut self,
-        timeout: std::time::Duration,
-    ) -> Result<SvcStatus, failure::Error> {
+    pub fn handle_msgs(&mut self, timeout: std::time::Duration) -> Result<SvcStatus> {
         let start = std::time::Instant::now();
         while start.elapsed() < timeout {
             let remaining = timeout

          
@@ 170,7 165,7 @@ impl DBusService {
     ///
     /// We don't really shut down until the connection object is destroyed which happens on
     /// [Drop].  This only unregisters the name and handles all outstanding messages.
-    pub fn shutdown(&self) -> Result<(), failure::Error> {
+    pub fn shutdown(&self) -> Result<()> {
         match self.connection.release_name(BUSNAME) {
             Ok(action) => info!("Releasing busname {}: {:?}", BUSNAME, action),
             Err(err) => error!("Failed releasing busname {}: {}", BUSNAME, err),

          
@@ 517,23 512,22 @@ impl<'a> Client<'a> {
     /// Terminates the daemon.
     ///
     /// This call is non-blocking.
-    pub fn term(&self) -> Result<(), failure::Error> {
+    pub fn term(&self) -> Result<()> {
         let msg =
             dbus::Message::new_method_call(self.peer.clone(), MANAGER_PATH, MANAGER_IFACE, "Term")
                 .unwrap();
         self.conn
             .send(msg)
             .and(Ok(()))
-            .map_err(|_| failure::err_msg("Failed sending Term() message"))
+            .map_err(|_| anyhow::anyhow!("Failed sending Term() message"))
     }
 
     /// Pings the peer.
     ///
     /// # Errors
     ///
-    /// Returns a `ClientError` with a cause which is a
-    /// `failure::Context` which has a `ClientErrorKind::CallFailed`
-    /// context if the peer did not respond.
+    /// Returns a `ClientError` with a cause which is a which has a
+    /// `ClientErrorKind::CallFailed` context if the peer did not respond.
     pub fn ping(&self) -> Result<(), ClientError> {
         let meth = dbus::Message::new_method_call(
             self.peer.clone(),