Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Raveline
Copy link

@Raveline Raveline commented Jun 3, 2025

Add an ultimate log if an uncaught exception interrupt the effects being run.

(`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
Copy link
Member

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).

@@ -12,8 +12,9 @@ module Effectful.Log
, module Log
) where

import Control.Exception.Lifted
Copy link
Member

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.

time <- liftIO getCurrentTime
logEnv <- getLoggerEnv
liftIO $
logMessageIO logEnv time LogAttention "Uncaught exception" $ object ["error" .= (pack . show $ e)]
Copy link
Member

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).

(`local` unlift action) $ \logEnv -> logEnv { leMaxLogLevel = level }
GetLoggerEnv -> ask
runLog component logger maxLogLevel =
reinterpret reader (\env -> \case
Copy link
Member

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.

logEnv <- getLoggerEnv
liftIO $
logMessageIO logEnv time LogAttention "Uncaught exception" $ object ["error" .= (pack . show $ e)]
throw e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throwIO

@arybczak
Copy link
Member

Ah, also needs a bump to 1.2.0.0 and a changelog entry.

Copy link
Contributor

@mmhat mmhat left a 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

@arybczak
Copy link
Member

Why? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants