-
Notifications
You must be signed in to change notification settings - Fork 372
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
#1762
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,6 @@ packages: | |
- ./yesod | ||
- ./yesod-eventsource | ||
- ./yesod-websockets | ||
|
||
extra-deps: | ||
- annotated-exception-0.1.2.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import qualified Control.Exception as EUnsafe | |
import Yesod.Core.Internal.Response | ||
import Data.ByteString.Builder (toLazyByteString) | ||
import qualified Data.ByteString.Lazy as BL | ||
import Control.Exception.Annotated (AnnotatedException (..)) | ||
import Control.Monad.IO.Class (MonadIO, liftIO) | ||
import Control.Monad.Logger (LogLevel (LevelError), LogSource, | ||
liftLoc) | ||
|
@@ -116,7 +117,7 @@ basicRunHandler rhe handler yreq resState = do | |
return (HCContent defaultStatus tc)) | ||
(\e -> | ||
case fromException e of | ||
Just e' -> return e' | ||
Just (AnnotatedException _ e') -> return e' | ||
Nothing -> HCError <$> toErrorHandler e) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 e0 So I think this function needs to also check for -- | 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 text Fortunately this should work fine - perhaps we want to unwrap the |
||
|
||
-- Get the raw state and return | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: yesod-core | ||
version: 1.6.22.1 | ||
version: 1.6.22.2 | ||
license: MIT | ||
license-file: LICENSE | ||
author: Michael Snoyman <[email protected]> | ||
|
@@ -27,6 +27,7 @@ library | |
|
||
build-depends: base >= 4.10 && < 5 | ||
, aeson >= 1.0 | ||
, annotated-exception >= 0.1.0.0 | ||
, auto-update | ||
, blaze-html >= 0.5 | ||
, blaze-markup >= 0.7.1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deserves a bit of commentary.
The
instance Exception e => Exception (AnnotatedException e)
has a slightlymagicalterriblehorrifyingunusual implementation offromException
.The tests for this demonstrate the pattern, but tl;dr, the
Exception
instance here onAnnotatedException
will work to catch both anAnnotatedException HandlerContents
and aHandlerContents
, which is then promoted toAnnotatedException mempty (hc :: HandlerContents)
.