From 51d5535a9b4c513fb96daa2bd8b1bcb71fdebb2f Mon Sep 17 00:00:00 2001 From: bobtwinkles Date: Mon, 29 Oct 2018 22:04:10 -0400 Subject: Improved handling of missing thermal zone files Instead of simply displaying zero when reading the thermal zone file fails, display whatever we would display when provided with a misconfigured thermal zone. --- src/Plugins/Monitors/ThermalZone.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Plugins/Monitors/ThermalZone.hs b/src/Plugins/Monitors/ThermalZone.hs index 838a7f5..a4744b4 100644 --- a/src/Plugins/Monitors/ThermalZone.hs +++ b/src/Plugins/Monitors/ThermalZone.hs @@ -34,12 +34,16 @@ runThermalZone :: [String] -> Monitor String runThermalZone args = do let zone = head args file = "/sys/class/thermal/thermal_zone" ++ zone ++ "/temp" - handleIOError :: IOException -> IO B.ByteString - handleIOError _ = return (B.pack "-1") + handleIOError :: IOException -> IO (Maybe B.ByteString) + handleIOError _ = return Nothing parse = return . (read :: String -> Int) . B.unpack exists <- io $ fileExist file if exists - then do mdegrees <- io $ catch ( B.readFile file) handleIOError >>= parse - temp <- showWithColors show (mdegrees `quot` 1000) - parseTemplate [ temp ] + then do contents <- io $ catch (fmap Just $ B.readFile file) handleIOError + case contents of + Just d -> do + mdegrees <- parse d + temp <- showWithColors show (mdegrees `quot` 1000) + parseTemplate [ temp ] + Nothing -> getConfigValue naString else getConfigValue naString -- cgit v1.2.3