diff --git a/homekit-controller/src/lib.rs b/homekit-controller/src/lib.rs index 62a989e..19485c3 100644 --- a/homekit-controller/src/lib.rs +++ b/homekit-controller/src/lib.rs @@ -311,15 +311,17 @@ impl DeviceConnection { self.characteristics_request(true), ) .await + .map_err(|_| HomekitError::Timeout) + .flatten_result() { - Ok(r) => r, - Err(_) => { + Ok(r) => Ok(r), + Err(e) => { log::warn!( - "{}failed to update characteristics", + "{}failed to update characteristics: {e:?}", formatted_name(&self.name) ); self.socket = None; - Err(HomekitError::Timeout) + Err(e) } } } @@ -432,6 +434,24 @@ pub enum HomekitError { NoData, } +trait FlattenResult { + type T; + type E; + fn flatten_result(self) -> Result; +} + +impl FlattenResult for Result, E> { + type T = T; + type E = E; + + fn flatten_result(self) -> Result { + match self { + Ok(v) => v, + Err(e) => Err(e), + } + } +} + #[derive(Debug, Error)] pub enum ConnectionError { #[error("http")]