Skip to content

Support annotated-exception #1761

@parsonsmatt

Description

@parsonsmatt

annotated-exception wraps exceptions in a semipermeable AnnotatedException e type, such that catching AnnotatedException e will also catch a thrown e (and provide a mempty for the annotations). So,

catchAnnotated :: Exception e => IO a -> (AnnotatedException e -> IO a) -> IO a
catchAnnotated = Control.Exception.catch

will never let an e escape.

However, only the catch and try functions in annotated-exception will also "see through" the AnnotatedException e and allow you to catch a plain e.

catchUnAnnotated :: Exception e => IO a (e -> IO a) -> IO a
catchUnAnnotated = Control.Exception.Annotated.catch

yesod currently uses HandlerContents as an exception to short-circuit execution of a handler. If an application is using AnnotatedException, then the current exception catching facilities will fail to handle an AnnotatedException HandlerContents as a HandlerContents, and will instead fail.

You can work around this by defining an exception handling middleware:

removeAnnotatedException :: HandlerFor site a -> HandlerFor site a
removeAnnotatedException action =
    action `catch` \(AnnotatedException _ (e :: SomeException)) ->
        throwIO e

But this would "just work" if yesod were integrated with annotated-exception, if only to catch the HandlerContents.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions