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

Support annotated-exception #1761

Open
parsonsmatt opened this issue Apr 13, 2022 · 0 comments · May be fixed by #1762
Open

Support annotated-exception #1761

parsonsmatt opened this issue Apr 13, 2022 · 0 comments · May be fixed by #1762

Comments

@parsonsmatt
Copy link
Contributor

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.

@parsonsmatt parsonsmatt linked a pull request Apr 13, 2022 that will close this issue
5 tasks
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 a pull request may close this issue.

1 participant