Conversation
|
I've made a PR to add |
| (\e -> | ||
| case fromException e of | ||
| Just e' -> return e' | ||
| Just (AnnotatedException _ e') -> return e' |
There was a problem hiding this comment.
This deserves a bit of commentary.
The instance Exception e => Exception (AnnotatedException e) has a slightly magical terrible horrifying unusual implementation of fromException.
The tests for this demonstrate the pattern, but tl;dr, the Exception instance here on AnnotatedException will work to catch both an AnnotatedException HandlerContents and a HandlerContents, which is then promoted to AnnotatedException mempty (hc :: HandlerContents).
|
Hi Matt, |
|
I'm happy to let this sit until folks feel good integrating it. At the very least, the issue and PR presence is useful for folks that inevitably run into trouble when using |
|
I’m OK with the change if you find this useful. But there are merge conflicts now, sorry for the delayed review |
|
@parsonsmatt do you need help finishing this? I'm interested |
|
I need to verify that the |
parsonsmatt
left a comment
There was a problem hiding this comment.
We have a Yesod middleware at work that handles this unwrapping, and as long as it's the last middleware, everything works fine.
I want to write some tests and verify that this is properly integrated before recommending merging.
| case fromException e of | ||
| Just e' -> return e' | ||
| Just (AnnotatedException _ e') -> return e' | ||
| Nothing -> HCError <$> toErrorHandler e) |
There was a problem hiding this comment.
OK, digging into this some more:
-- | Convert a synchronous exception into an ErrorResponse
toErrorHandler :: SomeException -> IO ErrorResponse
toErrorHandler e0 = handleAny errFromShow $
case fromException e0 of
Just (HCError x) -> evaluate $!! x
_ -> errFromShow e0So I think this function needs to also check for AnnotatedException - since the fromException e0 :: Maybe HCContents won't work if the underlying application code is calling throwWithCallStack.
-- | Generate an @ErrorResponse@ based on the shown version of the exception
errFromShow :: SomeException -> IO ErrorResponse
errFromShow x = do
text <- evaluate (T.pack $ show x) `catchAny` \_ ->
return (T.pack "Yesod.Core.Internal.Run.errFromShow: show of an exception threw an exception")
return $ InternalError textFortunately this should work fine - perhaps we want to unwrap the AnnotatedException before showing it?
Fixes #1761
Before submitting your PR, check that you've:
@sincedeclarations to the Haddocks for new, public APIsAfter submitting your PR: