@@ -16,6 +16,7 @@ module Network.Bugsnag.BeforeNotify
16
16
-- * Modifying the Event
17
17
, updateEvent
18
18
, updateEventFromOriginalException
19
+ , updateEventFromOriginalAnnotatedException
19
20
, setGroupingHash
20
21
, setGroupingHashBy
21
22
, setDevice
@@ -29,6 +30,8 @@ module Network.Bugsnag.BeforeNotify
29
30
import Prelude
30
31
31
32
import qualified Control.Exception as Exception
33
+ import Control.Exception.Annotated (AnnotatedException )
34
+ import qualified Control.Exception.Annotated as Annotated
32
35
import Data.Bugsnag
33
36
import Data.Maybe (isJust )
34
37
import Data.Text (Text , unpack )
@@ -123,9 +126,22 @@ updateEvent f = beforeNotify $ \_e event -> f event
123
126
--
124
127
-- If the cast fails, the event is unchanged.
125
128
--
129
+ -- The cast will match either @e@ or @'AnnotatedException' e@.
130
+ --
126
131
updateEventFromOriginalException
127
132
:: forall e . Exception. Exception e => (e -> BeforeNotify ) -> BeforeNotify
128
- updateEventFromOriginalException f = beforeNotify $ \ e event ->
133
+ updateEventFromOriginalException f =
134
+ updateEventFromOriginalAnnotatedException (f . Annotated. exception)
135
+
136
+ -- | Like 'updateEventFromOriginalException', but gives the result
137
+ -- as an 'AnnotatedException'
138
+ --
139
+ -- If the original exception was not wrapped in 'AnnotatedException', it
140
+ -- will match as an 'AnnotatedException' with an empty annotation list.
141
+ updateEventFromOriginalAnnotatedException
142
+ :: forall e . Exception. Exception e
143
+ => (AnnotatedException e -> BeforeNotify ) -> BeforeNotify
144
+ updateEventFromOriginalAnnotatedException f = beforeNotify $ \ e event ->
129
145
let bn = maybe mempty f $ Exception. fromException $ Exception. toException e
130
146
in runBeforeNotify bn e event
131
147
0 commit comments