Skip to content
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

Restyle support annotations, update stack configs #87

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bugsnag/src/Network/Bugsnag/BeforeNotify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ updateEvent f = beforeNotify $ \_e event -> f event
updateEventFromOriginalException
:: forall e . Exception.Exception e => (e -> BeforeNotify) -> BeforeNotify
updateEventFromOriginalException f = beforeNotify $ \e event ->
let bn = maybe mempty (f . Annotated.exception) $ Exception.fromException $ Exception.toException e
let
bn =
maybe mempty (f . Annotated.exception)
$ Exception.fromException
$ Exception.toException e
in runBeforeNotify bn e event

setGroupingHash :: Text -> BeforeNotify
Expand Down
30 changes: 15 additions & 15 deletions bugsnag/src/Network/Bugsnag/MetaData.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-- | Working with Bugsnag's 'event_metaData' field
module Network.Bugsnag.MetaData
( MetaData (..)
, metaData
) where
( MetaData(..)
, metaData
) where

import Prelude

import Data.Aeson (KeyValue ((.=)), Object, Value (..), object)
import Data.Aeson (KeyValue((.=)), Object, Value(..), object)
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Types as Aeson
import qualified Data.Aeson.KeyMap
import qualified Data.Aeson.Types as Aeson

newtype MetaData = MetaData
{ unMetaData :: Object
Expand All @@ -21,24 +21,24 @@ instance Semigroup MetaData where
--
-- The chosen bias ensures that adding metadata in smaller scopes (later)
-- overrides values from larger scopes.
MetaData x <> MetaData y = MetaData $ unionObjects y x
where
unionObjects :: Object -> Object -> Object
unionObjects = Data.Aeson.KeyMap.unionWith unionValues
MetaData x <> MetaData y = MetaData $ unionObjects y x
where
unionObjects :: Object -> Object -> Object
unionObjects = Data.Aeson.KeyMap.unionWith unionValues

unionValues (Object a) (Object b) = Object $ unionObjects a b
unionValues a _ = a
unionValues (Object a) (Object b) = Object $ unionObjects a b
unionValues a _ = a

instance Monoid MetaData where
mempty = MetaData mempty
mempty = MetaData mempty

-- | Construct 'MetaData' from 'Pair's
metaData
:: Aeson.Key
:: Aeson.Key
-- ^ The Tab within which the values will display
-> [Aeson.Pair]
-> [Aeson.Pair]
-- ^ The Key-Values themselves
-> MetaData
-> MetaData
metaData key = MetaData . Data.Aeson.KeyMap.fromList . pure . (key .=) . object

-- $details
Expand Down
29 changes: 17 additions & 12 deletions bugsnag/src/Network/Bugsnag/Notify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ module Network.Bugsnag.Notify

import Prelude

import Control.Exception (SomeException, fromException, toException)
import qualified Control.Exception as Exception
import Control.Monad ( unless, (<=<) )
import Control.Exception.Annotated (AnnotatedException)
import qualified Control.Exception.Annotated as Annotated
import Control.Monad ((<=<), unless)
import Data.Annotation (tryAnnotations)
import Data.Bugsnag
import Data.Bugsnag.Settings
import Data.Foldable (fold)
import Data.List.NonEmpty (nonEmpty)
import Network.Bugsnag.BeforeNotify
import Network.Bugsnag.Exception
import Network.HTTP.Client.TLS (getGlobalManager)
import Control.Exception.Annotated (AnnotatedException)
import Network.Bugsnag.MetaData
import Data.List.NonEmpty (nonEmpty)
import Data.Foldable (fold)
import Data.Annotation (tryAnnotations)
import Control.Exception (SomeException, fromException, toException)
import qualified Control.Exception.Annotated as Annotated
import Network.HTTP.Client.TLS (getGlobalManager)

notifyBugsnag :: Exception.Exception e => Settings -> e -> IO ()
notifyBugsnag = notifyBugsnagWith mempty
Expand All @@ -35,15 +35,20 @@ reportEvent Settings {..} event = unless (null $ event_exceptions event) $ do
either settings_onNotifyException pure result

buildEvent :: Exception.Exception e => BeforeNotify -> e -> Event
buildEvent bn e = runBeforeNotify bn e
$ defaultEvent { event_exceptions = [ex], event_metaData = unMetaData <$> metaDataFromException e }
buildEvent bn e = runBeforeNotify bn e $ defaultEvent
{ event_exceptions = [ex]
, event_metaData = unMetaData <$> metaDataFromException e
}
where ex = bugsnagExceptionFromSomeException $ Exception.toException e

metaDataFromException :: Exception.Exception e => e -> Maybe MetaData
metaDataFromException = metaDataFromAnnotatedException <=< (fromException @(AnnotatedException SomeException) . toException)
metaDataFromException =
metaDataFromAnnotatedException
<=< (fromException @(AnnotatedException SomeException) . toException)

metaDataFromAnnotatedException :: AnnotatedException e -> Maybe MetaData
metaDataFromAnnotatedException = fmap fold . nonEmpty . fst . tryAnnotations . Annotated.annotations
metaDataFromAnnotatedException =
fmap fold . nonEmpty . fst . tryAnnotations . Annotated.annotations

globalBeforeNotify :: Settings -> BeforeNotify
globalBeforeNotify Settings {..} =
Expand Down
Loading