aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2023-12-05 14:07:13 -0700
committerJosh Rahm <rahm@google.com>2023-12-05 14:07:13 -0700
commit55116fbf09c5b9f8518d8d64385d70960c1507a2 (patch)
tree5b5eacb66ebbc705c397bd5c69f00ef7ab7e6bd8
parent12db6e459520f78cfa07cedbc45015f4090066a1 (diff)
downloadrde-55116fbf09c5b9f8518d8d64385d70960c1507a2.tar.gz
rde-55116fbf09c5b9f8518d8d64385d70960c1507a2.tar.bz2
rde-55116fbf09c5b9f8518d8d64385d70960c1507a2.zip
Catch printf exceptions in logs to avoid having rde crash for stupid reasons
-rw-r--r--src/Rahm/Desktop/Logger.hs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/Rahm/Desktop/Logger.hs b/src/Rahm/Desktop/Logger.hs
index 593f820..b8c2a74 100644
--- a/src/Rahm/Desktop/Logger.hs
+++ b/src/Rahm/Desktop/Logger.hs
@@ -6,6 +6,7 @@ module Rahm.Desktop.Logger
)
where
+import Control.Exception
import Control.Monad (forM_, join, when)
import Data.Time.LocalTime (getZonedTime)
import Text.Printf (PrintfArg, PrintfType, printf)
@@ -55,8 +56,12 @@ setLogLevel ll = do
logs :: (LoggerType r) => LogLevel -> String -> r
logs ll fmt = gp (printf fmt) $ \ss -> do
LoggerState ll' <- XS.get
- io $ do
- zoneTime <- getZonedTime
- when (ll >= ll') $
- forM_ (lines ss) $ \s ->
- putStrLn (printf "[%s %s] - %s" (take 23 $ show zoneTime) (show ll) s)
+ io $
+ catch
+ ( do
+ zoneTime <- getZonedTime
+ when (ll >= ll') $
+ forM_ (lines ss) $ \s ->
+ putStrLn (printf "[%s %s] - %s" (take 23 $ show zoneTime) (show ll) s)
+ )
+ (\error -> putStrLn $ "Error: " ++ show (error :: SomeException))