Skip to content

Commit

Permalink
Log uncaught IO exceptions in cargohold (#4352)
Browse files Browse the repository at this point in the history
* Log uncaught IO exceptions in cargohold

* Add CHANGELOG entry
  • Loading branch information
pcapriotti authored Nov 29, 2024
1 parent 76d2a48 commit d29db85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/5-internal/cargohold-errors
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Log uncaught IO exceptions in cargohold
14 changes: 11 additions & 3 deletions services/cargohold/src/CargoHold/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ import Bilge.RPC (HasRequestId (..))
import qualified CargoHold.AWS as AWS
import CargoHold.Options (AWSOpts, Opts, S3Compatibility (..), brig)
import qualified CargoHold.Options as Opt
import Control.Error (ExceptT, exceptT)
import Control.Exception (throw)
import Control.Error (ExceptT, runExceptT)
import Control.Exception (catch, throwIO)
import Control.Lens (lensField, lensRules, makeLensesWith, non, (.~), (?~), (^.))
import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow)
import Data.Id
Expand Down Expand Up @@ -241,4 +241,12 @@ executeBrigInteral action = do
type Handler = ExceptT Error App

runHandler :: Env -> Handler a -> IO a
runHandler e h = runAppT e (exceptT throw pure h)
runHandler env h =
catch
(runAppT env (runExceptT h) >>= either throwIO pure)
$ \(e :: SomeException) -> do
Log.err env.appLogger $
Log.msg ("IO Exception occurred" :: ByteString)
. Log.field "message" (displayException e)
. Log.field "request" (unRequestId env.requestId)
throwIO e

0 comments on commit d29db85

Please sign in to comment.