diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-12-19 05:06:06 +0100 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-12-19 05:06:06 +0100 |
commit | 7fd503bc560c256d8aa769343e69b766ddbc8c68 (patch) | |
tree | c6949601d6c22f118c896ae8b2bd4e28db3cff7e /Plugins/Monitors/Common.hs | |
parent | 35944478a10cee4bf5da299b8450f82f0177b655 (diff) | |
download | xmobar-7fd503bc560c256d8aa769343e69b766ddbc8c68.tar.gz xmobar-7fd503bc560c256d8aa769343e69b766ddbc8c68.tar.bz2 |
A bit better error handling in monitors
Diffstat (limited to 'Plugins/Monitors/Common.hs')
-rw-r--r-- | Plugins/Monitors/Common.hs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs index 78f6b0e..e177e19 100644 --- a/Plugins/Monitors/Common.hs +++ b/Plugins/Monitors/Common.hs @@ -206,10 +206,9 @@ doConfigOptions (o:oo) = runM :: [String] -> IO MConfig -> ([String] -> Monitor String) -> Int -> (String -> IO ()) -> IO () -runM args conf action r cb = loop +runM args conf action r cb = handle (cb . showException) loop where ac = doArgs args action - runAc c = handle (return . showException) (runReaderT ac c) - loop = conf >>= runAc >>= cb >> tenthSeconds r >> loop + loop = conf >>= runReaderT ac >>= cb >> tenthSeconds r >> loop showException :: SomeException -> String showException = ("error: "++) . show . flip asTypeOf undefined @@ -327,8 +326,8 @@ showWithUnits d n x padString :: Int -> Int -> String -> Bool -> String -> String padString mnw mxw pad pr s = let len = length s - rmin = if mnw == 0 then 1 else mnw - rmax = if mxw == 0 then max len rmin else mxw + rmin = if mnw <= 0 then 1 else mnw + rmax = if mxw <= 0 then max len rmin else mxw (rmn, rmx) = if rmin <= rmax then (rmin, rmax) else (rmax, rmin) rlen = min (max rmn len) rmx in if rlen < len then |