-
Notifications
You must be signed in to change notification settings - Fork 4
Log unhandled exceptions #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Log unhandled exceptions #13
Conversation
src/Effectful/Log.hs
Outdated
(`local` unlift action) $ \logEnv -> logEnv { leDomain = leDomain logEnv ++ [domain] } | ||
LocalMaxLogLevel level action -> localSeqUnlift env $ \unlift -> do | ||
(`local` unlift action) $ \logEnv -> logEnv { leMaxLogLevel = level } | ||
GetLoggerEnv -> ask) . handle logException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use withException
instead of handle
(needs effectful-core-2.6.0.0).
src/Effectful/Log.hs
Outdated
@@ -12,8 +12,9 @@ module Effectful.Log | |||
, module Log | |||
) where | |||
|
|||
import Control.Exception.Lifted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use Effectful.Exception
.
src/Effectful/Log.hs
Outdated
time <- liftIO getCurrentTime | ||
logEnv <- getLoggerEnv | ||
liftIO $ | ||
logMessageIO logEnv time LogAttention "Uncaught exception" $ object ["error" .= (pack . show $ e)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use logAttention here (and you don't need pack, same as in the log-base PR).
src/Effectful/Log.hs
Outdated
(`local` unlift action) $ \logEnv -> logEnv { leMaxLogLevel = level } | ||
GetLoggerEnv -> ask | ||
runLog component logger maxLogLevel = | ||
reinterpret reader (\env -> \case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think putting the handler in the where clause will be better for readability - right now it's somewhat hard to see the "handle" stuff at the end.
src/Effectful/Log.hs
Outdated
logEnv <- getLoggerEnv | ||
liftIO $ | ||
logMessageIO logEnv time LogAttention "Uncaught exception" $ object ["error" .= (pack . show $ e)] | ||
throw e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throwIO
Ah, also needs a bump to 1.2.0.0 and a changelog entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think I'd prefer if we could leave the original runLog
as it is now and introduce a new runLogWithException
(or something like that) that logs uncaught exceptions:
runLogWithException component logger maxLevel = runLog component logger maxLevel . handle logException
Why? 🤔 |
Add an ultimate log if an uncaught exception interrupt the effects being run.