Skip to content

Commit ad36627

Browse files
solmike-burns
authored andcommitted
Make sure, that no exceptions escape doHttps (see haskell-github#7)
1 parent 9a399fb commit ad36627

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

Github/Data/Definitions.hs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ module Github.Data.Definitions where
44

55
import Data.Time
66
import Data.Data
7-
import Network.HTTP.Conduit (HttpException(..))
87
import qualified Control.Exception as E
98

10-
deriving instance Eq Network.HTTP.Conduit.HttpException
11-
129
-- | Errors have been tagged according to their source, so you can more easily
1310
-- dispatch and handle them.
1411
data Error =
15-
HTTPConnectionError E.IOException -- ^ A HTTP error occurred. The actual caught error is included, if available.
12+
HTTPConnectionError E.SomeException -- ^ A HTTP error occurred. The actual caught error is included.
1613
| ParseError String -- ^ An error in the parser itself.
1714
| JsonError String -- ^ The JSON is malformed or unexpected.
1815
| UserError String -- ^ Incorrect input.
19-
deriving (Show, Eq)
16+
deriving Show
2017

2118
-- | A date in the Github format, which is a special case of ISO-8601.
2219
newtype GithubDate = GithubDate { fromGithubDate :: UTCTime }

Github/Private.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ githubAPI method url body = do
3737
result
3838
where encodedBody = RequestBodyLBS $ encode $ toJSON body
3939

40-
doHttps :: BS.ByteString -> String -> Maybe (RequestBody IO) -> IO (Either E.IOException (Response LBS.ByteString))
40+
doHttps :: BS.ByteString -> String -> Maybe (RequestBody IO) -> IO (Either E.SomeException (Response LBS.ByteString))
4141
doHttps method url body = do
4242
let (Just uri) = parseURI url
4343
(Just host) = uriRegName uri
@@ -52,7 +52,15 @@ doHttps method url body = do
5252
, queryString = queryString
5353
}
5454

55-
(getResponse request >>= return . Right) `catch` (return . Left)
55+
(getResponse request >>= return . Right) `E.catches` [
56+
-- Re-throw AsyncException, otherwise execution will not terminate on
57+
-- SIGINT (ctrl-c). All AsyncExceptions are re-thrown (not just
58+
-- UserInterrupt) because all of them indicate severe conditions and
59+
-- should not occur during normal operation.
60+
E.Handler (\e -> E.throw (e :: E.AsyncException)),
61+
62+
E.Handler (\e -> (return . Left) (e :: E.SomeException))
63+
]
5664
where
5765
getResponse request = withManager $ \manager -> httpLbs request manager
5866

0 commit comments

Comments
 (0)