From 5912e705267778bf486d0982ce4163bcf861f56a Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sun, 1 Jan 2023 19:52:01 -0500 Subject: [PATCH] ENH log errors for dbus property query --- lib/Data/Internal/DBus.hs | 15 +++++++++------ lib/Xmobar/Plugins/Bluetooth.hs | 16 ++++++++++++---- lib/Xmobar/Plugins/Device.hs | 6 +++++- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/Data/Internal/DBus.hs b/lib/Data/Internal/DBus.hs index 964066d..baf64a0 100644 --- a/lib/Data/Internal/DBus.hs +++ b/lib/Data/Internal/DBus.hs @@ -33,6 +33,7 @@ where import DBus import DBus.Client +import qualified Data.ByteString.Char8 as BC import RIO import qualified RIO.Map as M import qualified RIO.Text as T @@ -205,18 +206,20 @@ propertySignal :: MemberName propertySignal = memberName_ "PropertiesChanged" callPropertyGet - :: (MonadUnliftIO m, SafeClient c) + :: (MonadReader env m, HasLogFunc env, MonadUnliftIO m, SafeClient c) => BusName -> ObjectPath -> InterfaceName -> MemberName -> c -> m [Variant] -callPropertyGet bus path iface property cl = - liftIO $ - fmap (either (const []) (: [])) $ - getProperty (toClient cl) $ - methodCallBus bus path iface property +callPropertyGet bus path iface property cl = do + res <- liftIO $ getProperty (toClient cl) $ methodCallBus bus path iface property + case res of + Left err -> do + logError $ displayBytesUtf8 $ BC.pack $ methodErrorMessage err + return [] + Right v -> return [v] matchProperty :: Maybe BusName -> Maybe ObjectPath -> MatchRule matchProperty b p = diff --git a/lib/Xmobar/Plugins/Bluetooth.hs b/lib/Xmobar/Plugins/Bluetooth.hs index e3bfb92..4173ca8 100644 --- a/lib/Xmobar/Plugins/Bluetooth.hs +++ b/lib/Xmobar/Plugins/Bluetooth.hs @@ -213,7 +213,7 @@ pathCallback _ _ _ _ = return () -- Adapter initAdapter - :: (MonadUnliftIO m) + :: (MonadReader env m, HasLogFunc env, MonadUnliftIO m) => MutableBtState -> ObjectPath -> SysClient @@ -242,7 +242,11 @@ addAdaptorListener state dpy adaptor sys = do where procMatch = withSignalMatch $ \b -> putPowered state b >> dpy -callGetPowered :: MonadUnliftIO m => ObjectPath -> SysClient -> m [Variant] +callGetPowered + :: (MonadReader env m, HasLogFunc env, MonadUnliftIO m) + => ObjectPath + -> SysClient + -> m [Variant] callGetPowered adapter = callPropertyGet btBus adapter adapterInterface $ memberName_ $ @@ -279,7 +283,7 @@ addAndInitDevice state dpy device client = do forM_ sh $ \s -> initDevice state s device client initDevice - :: MonadUnliftIO m + :: (MonadReader env m, HasLogFunc env, MonadUnliftIO m) => MutableBtState -> SignalHandler -> ObjectPath @@ -310,7 +314,11 @@ addDeviceListener state dpy device sys = do matchConnected :: [Variant] -> SignalMatch Bool matchConnected = matchPropertyChanged devInterface devConnected -callGetConnected :: MonadUnliftIO m => ObjectPath -> SysClient -> m [Variant] +callGetConnected + :: (MonadReader env m, HasLogFunc env, MonadUnliftIO m) + => ObjectPath + -> SysClient + -> m [Variant] callGetConnected p = callPropertyGet btBus p devInterface $ memberName_ (T.unpack devConnected) diff --git a/lib/Xmobar/Plugins/Device.hs b/lib/Xmobar/Plugins/Device.hs index 967e5dd..220a297 100644 --- a/lib/Xmobar/Plugins/Device.hs +++ b/lib/Xmobar/Plugins/Device.hs @@ -52,7 +52,11 @@ getDevice sys iface = bodyToMaybe <$> callMethod' sys mc { methodCallBody = [toVariant iface] } -getDeviceConnected :: MonadUnliftIO m => ObjectPath -> SysClient -> m [Variant] +getDeviceConnected + :: (MonadReader env m, HasLogFunc env, MonadUnliftIO m) + => ObjectPath + -> SysClient + -> m [Variant] getDeviceConnected path = callPropertyGet networkManagerBus path nmDeviceInterface $ memberName_ $