on master help sign in
Drop `EitherT` in favor of `ExceptT`
commitf2f7b061d20dc85e3b647feb0d13ab35d1980f27 authorIndex Int <vlad.z.4096@gmail.com> dateSat 12 Sep 2015, 15:11 (11 years ago) parent961887c
22 files changed+158−174
servant-client/README.md+2−2 servant-client/servant-client.cabal+1−2 servant-client/src/Servant/Client.hs+30−30 servant-client/src/Servant/Common/Req.hs+9−9 servant-client/test/Servant/ClientSpec.hs+56−56 servant-examples/hackage/hackage.hs+5−5 servant-examples/servant-examples.cabal+1−3 servant-examples/tutorial/T3.hs+4−4 servant-examples/tutorial/T5.hs+2−2 servant-examples/tutorial/T7.hs+2−2 servant-examples/tutorial/T8.hs+6−6 servant-mock/src/Servant/Mock.hs+2−2 servant-server/CHANGELOG.md+1 servant-server/example/greet.hs+1−1 servant-server/servant-server.cabal−2 servant-server/src/Servant/Server.hs+1−5 servant-server/src/Servant/Server/Internal.hs+24−24 servant-server/src/Servant/Server/Internal/Enter.hs−8 servant-server/src/Servant/Server/Internal/RoutingApplication.hs+3−3 servant-server/test/Servant/Server/Internal/EnterSpec.hs+2−2 servant-server/test/Servant/ServerSpec.hs+5−5 stack.yaml+1−1
servant-client/README.md+2−2
@@ -13,8 +13,8 @@ type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
1313myApi :: Proxy MyApi
1414myApi = Proxy
1515
16−getAllBooks :: EitherT String IO [Book]
17−postNewBook :: Book -> EitherT String IO Book
16+getAllBooks :: ExceptT String IO [Book]
17+postNewBook :: Book -> ExceptT String IO Book
1818-- 'client' allows you to produce operations to query an API from a client.
1919(getAllBooks :<|> postNewBook) = client myApi host
2020 where host = BaseUrl Http "localhost" 8080
servant-client/servant-client.cabal+1−2
@@ -33,7 +33,6 @@ library
3333 , aeson
3434 , attoparsec
3535 , bytestring
36− , either
3736 , exceptions
3837 , http-client
3938 , http-client-tls
@@ -61,10 +60,10 @@ test-suite spec
6160 , Servant.Common.BaseUrlSpec
6261 build-depends:
6362 base == 4.*
63+ , transformers
6464 , aeson
6565 , bytestring
6666 , deepseq
67− , either
6867 , hspec == 2.*
6968 , http-client
7069 , http-media
servant-client/src/Servant/Client.hs+30−30
@@ -25,7 +25,7 @@ module Servant.Client
2525import Control.Applicative ((<$>))
2626#endif
2727import Control.Monad
28−import Control.Monad.Trans.Either
28+import Control.Monad.Trans.Except
2929import Data.ByteString.Lazy (ByteString)
3030import Data.List
3131import Data.Proxy
@@ -50,8 +50,8 @@ import Servant.Common.Req
5050-- > myApi :: Proxy MyApi
5151-- > myApi = Proxy
5252-- >
53−-- > getAllBooks :: EitherT String IO [Book]
54−-- > postNewBook :: Book -> EitherT String IO Book
53+-- > getAllBooks :: ExceptT String IO [Book]
54+-- > postNewBook :: Book -> ExceptT String IO Book
5555-- > (getAllBooks :<|> postNewBook) = client myApi host
5656-- > where host = BaseUrl Http "localhost" 8080
5757client :: HasClient layout => Proxy layout -> BaseUrl -> Client layout
@@ -76,8 +76,8 @@ class HasClient layout where
7676-- > myApi :: Proxy MyApi
7777-- > myApi = Proxy
7878-- >
79−-- > getAllBooks :: EitherT String IO [Book]
80−-- > postNewBook :: Book -> EitherT String IO Book
79+-- > getAllBooks :: ExceptT String IO [Book]
80+-- > postNewBook :: Book -> ExceptT String IO Book
8181-- > (getAllBooks :<|> postNewBook) = client myApi host
8282-- > where host = BaseUrl Http "localhost" 8080
8383instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
@@ -102,7 +102,7 @@ instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
102102-- > myApi :: Proxy MyApi
103103-- > myApi = Proxy
104104-- >
105−-- > getBook :: Text -> EitherT String IO Book
105+-- > getBook :: Text -> ExceptT String IO Book
106106-- > getBook = client myApi host
107107-- > where host = BaseUrl Http "localhost" 8080
108108-- > -- then you can just use "getBook" to query that endpoint
@@ -129,7 +129,7 @@ instance
129129#endif
130130 -- See https://downloads.haskell.org/~ghc/7.8.2/docs/html/users_guide/type-class-extensions.html#undecidable-instances
131131 (MimeUnrender ct a, cts' ~ (ct ': cts)) => HasClient (Delete cts' a) where
132− type Client (Delete cts' a) = EitherT ServantError IO a
132+ type Client (Delete cts' a) = ExceptT ServantError IO a
133133 clientWithRoute Proxy req baseurl =
134134 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
135135
@@ -140,7 +140,7 @@ instance
140140 {-# OVERLAPPING #-}
141141#endif
142142 HasClient (Delete cts ()) where
143− type Client (Delete cts ()) = EitherT ServantError IO ()
143+ type Client (Delete cts ()) = ExceptT ServantError IO ()
144144 clientWithRoute Proxy req baseurl =
145145 void $ performRequestNoBody H.methodDelete req [204] baseurl
146146
@@ -153,7 +153,7 @@ instance
153153 -- See https://downloads.haskell.org/~ghc/7.8.2/docs/html/users_guide/type-class-extensions.html#undecidable-instances
154154 ( MimeUnrender ct a, BuildHeadersTo ls, cts' ~ (ct ': cts)
155155 ) => HasClient (Delete cts' (Headers ls a)) where
156− type Client (Delete cts' (Headers ls a)) = EitherT ServantError IO (Headers ls a)
156+ type Client (Delete cts' (Headers ls a)) = ExceptT ServantError IO (Headers ls a)
157157 clientWithRoute Proxy req baseurl = do
158158 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
159159 return $ Headers { getResponse = resp
@@ -169,7 +169,7 @@ instance
169169 {-# OVERLAPPABLE #-}
170170#endif
171171 (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
172− type Client (Get (ct ': cts) result) = EitherT ServantError IO result
172+ type Client (Get (ct ': cts) result) = ExceptT ServantError IO result
173173 clientWithRoute Proxy req baseurl =
174174 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203] baseurl
175175
@@ -180,7 +180,7 @@ instance
180180 {-# OVERLAPPING #-}
181181#endif
182182 HasClient (Get (ct ': cts) ()) where
183− type Client (Get (ct ': cts) ()) = EitherT ServantError IO ()
183+ type Client (Get (ct ': cts) ()) = ExceptT ServantError IO ()
184184 clientWithRoute Proxy req baseurl =
185185 performRequestNoBody H.methodGet req [204] baseurl
186186
@@ -192,7 +192,7 @@ instance
192192#endif
193193 ( MimeUnrender ct a, BuildHeadersTo ls
194194 ) => HasClient (Get (ct ': cts) (Headers ls a)) where
195− type Client (Get (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
195+ type Client (Get (ct ': cts) (Headers ls a)) = ExceptT ServantError IO (Headers ls a)
196196 clientWithRoute Proxy req baseurl = do
197197 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203, 204] baseurl
198198 return $ Headers { getResponse = resp
@@ -220,7 +220,7 @@ instance
220220-- > myApi :: Proxy MyApi
221221-- > myApi = Proxy
222222-- >
223−-- > viewReferer :: Maybe Referer -> EitherT String IO Book
223+-- > viewReferer :: Maybe Referer -> ExceptT String IO Book
224224-- > viewReferer = client myApi host
225225-- > where host = BaseUrl Http "localhost" 8080
226226-- > -- then you can just use "viewRefer" to query that endpoint
@@ -250,7 +250,7 @@ instance
250250 {-# OVERLAPPABLE #-}
251251#endif
252252 (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
253− type Client (Post (ct ': cts) a) = EitherT ServantError IO a
253+ type Client (Post (ct ': cts) a) = ExceptT ServantError IO a
254254 clientWithRoute Proxy req baseurl =
255255 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPost req [200,201] baseurl
256256
@@ -261,7 +261,7 @@ instance
261261 {-# OVERLAPPING #-}
262262#endif
263263 HasClient (Post (ct ': cts) ()) where
264− type Client (Post (ct ': cts) ()) = EitherT ServantError IO ()
264+ type Client (Post (ct ': cts) ()) = ExceptT ServantError IO ()
265265 clientWithRoute Proxy req baseurl =
266266 void $ performRequestNoBody H.methodPost req [204] baseurl
267267
@@ -273,7 +273,7 @@ instance
273273#endif
274274 ( MimeUnrender ct a, BuildHeadersTo ls
275275 ) => HasClient (Post (ct ': cts) (Headers ls a)) where
276− type Client (Post (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
276+ type Client (Post (ct ': cts) (Headers ls a)) = ExceptT ServantError IO (Headers ls a)
277277 clientWithRoute Proxy req baseurl = do
278278 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPost req [200, 201] baseurl
279279 return $ Headers { getResponse = resp
@@ -289,7 +289,7 @@ instance
289289 {-# OVERLAPPABLE #-}
290290#endif
291291 (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
292− type Client (Put (ct ': cts) a) = EitherT ServantError IO a
292+ type Client (Put (ct ': cts) a) = ExceptT ServantError IO a
293293 clientWithRoute Proxy req baseurl =
294294 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPut req [200,201] baseurl
295295
@@ -300,7 +300,7 @@ instance
300300 {-# OVERLAPPING #-}
301301#endif
302302 HasClient (Put (ct ': cts) ()) where
303− type Client (Put (ct ': cts) ()) = EitherT ServantError IO ()
303+ type Client (Put (ct ': cts) ()) = ExceptT ServantError IO ()
304304 clientWithRoute Proxy req baseurl =
305305 void $ performRequestNoBody H.methodPut req [204] baseurl
306306
@@ -312,7 +312,7 @@ instance
312312#endif
313313 ( MimeUnrender ct a, BuildHeadersTo ls
314314 ) => HasClient (Put (ct ': cts) (Headers ls a)) where
315− type Client (Put (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
315+ type Client (Put (ct ': cts) (Headers ls a)) = ExceptT ServantError IO (Headers ls a)
316316 clientWithRoute Proxy req baseurl = do
317317 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPut req [200, 201] baseurl
318318 return $ Headers { getResponse = resp
@@ -328,7 +328,7 @@ instance
328328 {-# OVERLAPPABLE #-}
329329#endif
330330 (MimeUnrender ct a) => HasClient (Patch (ct ': cts) a) where
331− type Client (Patch (ct ': cts) a) = EitherT ServantError IO a
331+ type Client (Patch (ct ': cts) a) = ExceptT ServantError IO a
332332 clientWithRoute Proxy req baseurl =
333333 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200,201] baseurl
334334
@@ -339,7 +339,7 @@ instance
339339 {-# OVERLAPPING #-}
340340#endif
341341 HasClient (Patch (ct ': cts) ()) where
342− type Client (Patch (ct ': cts) ()) = EitherT ServantError IO ()
342+ type Client (Patch (ct ': cts) ()) = ExceptT ServantError IO ()
343343 clientWithRoute Proxy req baseurl =
344344 void $ performRequestNoBody H.methodPatch req [204] baseurl
345345
@@ -351,7 +351,7 @@ instance
351351#endif
352352 ( MimeUnrender ct a, BuildHeadersTo ls
353353 ) => HasClient (Patch (ct ': cts) (Headers ls a)) where
354− type Client (Patch (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
354+ type Client (Patch (ct ': cts) (Headers ls a)) = ExceptT ServantError IO (Headers ls a)
355355 clientWithRoute Proxy req baseurl = do
356356 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200, 201, 204] baseurl
357357 return $ Headers { getResponse = resp
@@ -378,7 +378,7 @@ instance
378378-- > myApi :: Proxy MyApi
379379-- > myApi = Proxy
380380-- >
381−-- > getBooksBy :: Maybe Text -> EitherT String IO [Book]
381+-- > getBooksBy :: Maybe Text -> ExceptT String IO [Book]
382382-- > getBooksBy = client myApi host
383383-- > where host = BaseUrl Http "localhost" 8080
384384-- > -- then you can just use "getBooksBy" to query that endpoint.
@@ -424,7 +424,7 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
424424-- > myApi :: Proxy MyApi
425425-- > myApi = Proxy
426426-- >
427−-- > getBooksBy :: [Text] -> EitherT String IO [Book]
427+-- > getBooksBy :: [Text] -> ExceptT String IO [Book]
428428-- > getBooksBy = client myApi host
429429-- > where host = BaseUrl Http "localhost" 8080
430430-- > -- then you can just use "getBooksBy" to query that endpoint.
@@ -465,7 +465,7 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
465465-- > myApi :: Proxy MyApi
466466-- > myApi = Proxy
467467-- >
468−-- > getBooks :: Bool -> EitherT String IO [Book]
468+-- > getBooks :: Bool -> ExceptT String IO [Book]
469469-- > getBooks = client myApi host
470470-- > where host = BaseUrl Http "localhost" 8080
471471-- > -- then you can just use "getBooks" to query that endpoint.
@@ -507,7 +507,7 @@ instance (KnownSymbol sym, HasClient sublayout)
507507-- > myApi :: Proxy MyApi
508508-- > myApi = Proxy
509509-- >
510−-- > getBooksBy :: Maybe Text -> EitherT String IO [Book]
510+-- > getBooksBy :: Maybe Text -> ExceptT String IO [Book]
511511-- > getBooksBy = client myApi host
512512-- > where host = BaseUrl Http "localhost" 8080
513513-- > -- then you can just use "getBooksBy" to query that endpoint.
@@ -552,7 +552,7 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
552552-- > myApi :: Proxy MyApi
553553-- > myApi = Proxy
554554-- >
555−-- > getBooksBy :: [Text] -> EitherT String IO [Book]
555+-- > getBooksBy :: [Text] -> ExceptT String IO [Book]
556556-- > getBooksBy = client myApi host
557557-- > where host = BaseUrl Http "localhost" 8080
558558-- > -- then you can just use "getBooksBy" to query that endpoint.
@@ -593,7 +593,7 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
593593-- > myApi :: Proxy MyApi
594594-- > myApi = Proxy
595595-- >
596−-- > getBooks :: Bool -> EitherT String IO [Book]
596+-- > getBooks :: Bool -> ExceptT String IO [Book]
597597-- > getBooks = client myApi host
598598-- > where host = BaseUrl Http "localhost" 8080
599599-- > -- then you can just use "getBooks" to query that endpoint.
@@ -618,7 +618,7 @@ instance (KnownSymbol sym, HasClient sublayout)
618618-- | Pick a 'Method' and specify where the server you want to query is. You get
619619-- back the full `Response`.
620620instance HasClient Raw where
621− type Client Raw = H.Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
621+ type Client Raw = H.Method -> ExceptT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
622622
623623 clientWithRoute :: Proxy Raw -> Req -> BaseUrl -> Client Raw
624624 clientWithRoute Proxy req baseurl httpMethod = do
@@ -639,7 +639,7 @@ instance HasClient Raw where
639639-- > myApi :: Proxy MyApi
640640-- > myApi = Proxy
641641-- >
642−-- > addBook :: Book -> EitherT String IO Book
642+-- > addBook :: Book -> ExceptT String IO Book
643643-- > addBook = client myApi host
644644-- > where host = BaseUrl Http "localhost" 8080
645645-- > -- then you can just use "addBook" to query that endpoint
servant-client/src/Servant/Common/Req.hs+9−9
@@ -11,7 +11,7 @@ import Control.Exception
1111import Control.Monad
1212import Control.Monad.Catch (MonadThrow)
1313import Control.Monad.IO.Class
14−import Control.Monad.Trans.Either
14+import Control.Monad.Trans.Except
1515import Data.ByteString.Lazy hiding (pack, filter, map, null, elem)
1616import Data.IORef
1717import Data.String
@@ -142,7 +142,7 @@ displayHttpRequest httpmethod = "HTTP " ++ cs httpmethod ++ " request"
142142
143143
144144performRequest :: Method -> Req -> (Int -> Bool) -> BaseUrl
145− -> EitherT ServantError IO ( Int, ByteString, MediaType
145+ -> ExceptT ServantError IO ( Int, ByteString, MediaType
146146 , [HTTP.Header], Response ByteString)
147147performRequest reqMethod req isWantedStatus reqHost = do
148148 partialRequest <- liftIO $ reqToRequest req reqHost
@@ -156,7 +156,7 @@ performRequest reqMethod req isWantedStatus reqHost = do
156156 Client.httpLbs request manager
157157 case eResponse of
158158 Left err ->
159− left . ConnectionError $ SomeException err
159+ throwE . ConnectionError $ SomeException err
160160
161161 Right response -> do
162162 let status = Client.responseStatus response
@@ -166,25 +166,25 @@ performRequest reqMethod req isWantedStatus reqHost = do
166166 ct <- case lookup "Content-Type" $ Client.responseHeaders response of
167167 Nothing -> pure $ "application"//"octet-stream"
168168 Just t -> case parseAccept t of
169− Nothing -> left $ InvalidContentTypeHeader (cs t) body
169+ Nothing -> throwE $ InvalidContentTypeHeader (cs t) body
170170 Just t' -> pure t'
171171 unless (isWantedStatus status_code) $
172− left $ FailureResponse status ct body
172+ throwE $ FailureResponse status ct body
173173 return (status_code, body, ct, hrds, response)
174174
175175
176176performRequestCT :: MimeUnrender ct result =>
177− Proxy ct -> Method -> Req -> [Int] -> BaseUrl -> EitherT ServantError IO ([HTTP.Header], result)
177+ Proxy ct -> Method -> Req -> [Int] -> BaseUrl -> ExceptT ServantError IO ([HTTP.Header], result)
178178performRequestCT ct reqMethod req wantedStatus reqHost = do
179179 let acceptCT = contentType ct
180180 (_status, respBody, respCT, hrds, _response) <-
181181 performRequest reqMethod (req { reqAccept = [acceptCT] }) (`elem` wantedStatus) reqHost
182− unless (matches respCT (acceptCT)) $ left $ UnsupportedContentType respCT respBody
182+ unless (matches respCT (acceptCT)) $ throwE $ UnsupportedContentType respCT respBody
183183 case mimeUnrender ct respBody of
184− Left err -> left $ DecodeFailure err respCT respBody
184+ Left err -> throwE $ DecodeFailure err respCT respBody
185185 Right val -> return (hrds, val)
186186
187−performRequestNoBody :: Method -> Req -> [Int] -> BaseUrl -> EitherT ServantError IO ()
187+performRequestNoBody :: Method -> Req -> [Int] -> BaseUrl -> ExceptT ServantError IO ()
188188performRequestNoBody reqMethod req wantedStatus reqHost = do
189189 _ <- performRequest reqMethod req (`elem` wantedStatus) reqHost
190190 return ()
servant-client/test/Servant/ClientSpec.hs+56−56
@@ -13,12 +13,12 @@
1313module Servant.ClientSpec where
1414
1515#if !MIN_VERSION_base(4,8,0)
16−import Control.Applicative ((<$>))
16+import Control.Applicative ((<$>))
1717#endif
18−import qualified Control.Arrow as Arrow
18+import Control.Arrow (left)
1919import Control.Concurrent
2020import Control.Exception
21−import Control.Monad.Trans.Either
21+import Control.Monad.Trans.Except
2222import Data.Aeson
2323import Data.ByteString.Lazy (ByteString)
2424import Data.Char
@@ -105,14 +105,14 @@ server = serve api (
105105 :<|> return
106106 :<|> (\ name -> case name of
107107 Just "alice" -> return alice
108− Just name -> left $ ServantErr 400 (name ++ " not found") "" []
109− Nothing -> left $ ServantErr 400 "missing parameter" "" [])
108+ Just name -> throwE $ ServantErr 400 (name ++ " not found") "" []
109+ Nothing -> throwE $ ServantErr 400 "missing parameter" "" [])
110110 :<|> (\ names -> return (zipWith Person names [0..]))
111111 :<|> return
112112 :<|> (\ name -> case name of
113113 Just "alice" -> return alice
114− Just name -> left $ ServantErr 400 (name ++ " not found") "" []
115− Nothing -> left $ ServantErr 400 "missing parameter" "" [])
114+ Just name -> throwE $ ServantErr 400 (name ++ " not found") "" []
115+ Nothing -> throwE $ ServantErr 400 "missing parameter" "" [])
116116 :<|> (\ names -> return (zipWith Person names [0..]))
117117 :<|> return
118118 :<|> (\ _request respond -> respond $ responseLBS ok200 [] "rawSuccess")
@@ -144,21 +144,21 @@ withFailServer action = withWaiDaemon (return failServer) action
144144
145145spec :: IO ()
146146spec = withServer $ \ baseUrl -> do
147− let getGet :: EitherT ServantError IO Person
148− getDeleteEmpty :: EitherT ServantError IO ()
149− getCapture :: String -> EitherT ServantError IO Person
150− getBody :: Person -> EitherT ServantError IO Person
151− getQueryParam :: Maybe String -> EitherT ServantError IO Person
152− getQueryParams :: [String] -> EitherT ServantError IO [Person]
153− getQueryFlag :: Bool -> EitherT ServantError IO Bool
154− getMatrixParam :: Maybe String -> EitherT ServantError IO Person
155− getMatrixParams :: [String] -> EitherT ServantError IO [Person]
156− getMatrixFlag :: Bool -> EitherT ServantError IO Bool
157− getRawSuccess :: Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
158− getRawFailure :: Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
159− getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])] -> EitherT ServantError IO (String, Maybe Int, Bool, [(String, [Rational])])
160− getRespHeaders :: EitherT ServantError IO (Headers TestHeaders Bool)
161− getDeleteContentType :: EitherT ServantError IO ()
147+ let getGet :: ExceptT ServantError IO Person
148+ getDeleteEmpty :: ExceptT ServantError IO ()
149+ getCapture :: String -> ExceptT ServantError IO Person
150+ getBody :: Person -> ExceptT ServantError IO Person
151+ getQueryParam :: Maybe String -> ExceptT ServantError IO Person
152+ getQueryParams :: [String] -> ExceptT ServantError IO [Person]
153+ getQueryFlag :: Bool -> ExceptT ServantError IO Bool
154+ getMatrixParam :: Maybe String -> ExceptT ServantError IO Person
155+ getMatrixParams :: [String] -> ExceptT ServantError IO [Person]
156+ getMatrixFlag :: Bool -> ExceptT ServantError IO Bool
157+ getRawSuccess :: Method -> ExceptT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
158+ getRawFailure :: Method -> ExceptT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
159+ getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])] -> ExceptT ServantError IO (String, Maybe Int, Bool, [(String, [Rational])])
160+ getRespHeaders :: ExceptT ServantError IO (Headers TestHeaders Bool)
161+ getDeleteContentType :: ExceptT ServantError IO ()
162162 ( getGet
163163 :<|> getDeleteEmpty
164164 :<|> getCapture
@@ -178,54 +178,54 @@ spec = withServer $ \ baseUrl -> do
178178
179179 hspec $ do
180180 it "Servant.API.Get" $ do
181− (Arrow.left show <$> runEitherT getGet) `shouldReturn` Right alice
181+ (left show <$> runExceptT getGet) `shouldReturn` Right alice
182182
183183 describe "Servant.API.Delete" $ do
184184 it "allows empty content type" $ do
185− (Arrow.left show <$> runEitherT getDeleteEmpty) `shouldReturn` Right ()
185+ (left show <$> runExceptT getDeleteEmpty) `shouldReturn` Right ()
186186
187187 it "allows content type" $ do
188− (Arrow.left show <$> runEitherT getDeleteContentType) `shouldReturn` Right ()
188+ (left show <$> runExceptT getDeleteContentType) `shouldReturn` Right ()
189189
190190 it "Servant.API.Capture" $ do
191− (Arrow.left show <$> runEitherT (getCapture "Paula")) `shouldReturn` Right (Person "Paula" 0)
191+ (left show <$> runExceptT (getCapture "Paula")) `shouldReturn` Right (Person "Paula" 0)
192192
193193 it "Servant.API.ReqBody" $ do
194194 let p = Person "Clara" 42
195− (Arrow.left show <$> runEitherT (getBody p)) `shouldReturn` Right p
195+ (left show <$> runExceptT (getBody p)) `shouldReturn` Right p
196196
197197 it "Servant.API.QueryParam" $ do
198− Arrow.left show <$> runEitherT (getQueryParam (Just "alice")) `shouldReturn` Right alice
199− Left FailureResponse{..} <- runEitherT (getQueryParam (Just "bob"))
198+ left show <$> runExceptT (getQueryParam (Just "alice")) `shouldReturn` Right alice
199+ Left FailureResponse{..} <- runExceptT (getQueryParam (Just "bob"))
200200 responseStatus `shouldBe` Status 400 "bob not found"
201201
202202 it "Servant.API.QueryParam.QueryParams" $ do
203− (Arrow.left show <$> runEitherT (getQueryParams [])) `shouldReturn` Right []
204− (Arrow.left show <$> runEitherT (getQueryParams ["alice", "bob"]))
203+ (left show <$> runExceptT (getQueryParams [])) `shouldReturn` Right []
204+ (left show <$> runExceptT (getQueryParams ["alice", "bob"]))
205205 `shouldReturn` Right [Person "alice" 0, Person "bob" 1]
206206
207207 context "Servant.API.QueryParam.QueryFlag" $
208208 forM_ [False, True] $ \ flag ->
209209 it (show flag) $ do
210− (Arrow.left show <$> runEitherT (getQueryFlag flag)) `shouldReturn` Right flag
210+ (left show <$> runExceptT (getQueryFlag flag)) `shouldReturn` Right flag
211211
212212 it "Servant.API.MatrixParam" $ do
213− Arrow.left show <$> runEitherT (getMatrixParam (Just "alice")) `shouldReturn` Right alice
214− Left FailureResponse{..} <- runEitherT (getMatrixParam (Just "bob"))
213+ left show <$> runExceptT (getMatrixParam (Just "alice")) `shouldReturn` Right alice
214+ Left FailureResponse{..} <- runExceptT (getMatrixParam (Just "bob"))
215215 responseStatus `shouldBe` Status 400 "bob not found"
216216
217217 it "Servant.API.MatrixParam.MatrixParams" $ do
218− Arrow.left show <$> runEitherT (getMatrixParams []) `shouldReturn` Right []
219− Arrow.left show <$> runEitherT (getMatrixParams ["alice", "bob"])
218+ left show <$> runExceptT (getMatrixParams []) `shouldReturn` Right []
219+ left show <$> runExceptT (getMatrixParams ["alice", "bob"])
220220 `shouldReturn` Right [Person "alice" 0, Person "bob" 1]
221221
222222 context "Servant.API.MatrixParam.MatrixFlag" $
223223 forM_ [False, True] $ \ flag ->
224224 it (show flag) $ do
225− Arrow.left show <$> runEitherT (getMatrixFlag flag) `shouldReturn` Right flag
225+ left show <$> runExceptT (getMatrixFlag flag) `shouldReturn` Right flag
226226
227227 it "Servant.API.Raw on success" $ do
228− res <- runEitherT (getRawSuccess methodGet)
228+ res <- runExceptT (getRawSuccess methodGet)
229229 case res of
230230 Left e -> assertFailure $ show e
231231 Right (code, body, ct, _, response) -> do
@@ -234,7 +234,7 @@ spec = withServer $ \ baseUrl -> do
234234 C.responseStatus response `shouldBe` ok200
235235
236236 it "Servant.API.Raw on failure" $ do
237− res <- runEitherT (getRawFailure methodGet)
237+ res <- runExceptT (getRawFailure methodGet)
238238 case res of
239239 Left e -> assertFailure $ show e
240240 Right (code, body, ct, _, response) -> do
@@ -243,7 +243,7 @@ spec = withServer $ \ baseUrl -> do
243243 C.responseStatus response `shouldBe` badRequest400
244244
245245 it "Returns headers appropriately" $ withServer $ \ _ -> do
246− res <- runEitherT getRespHeaders
246+ res <- runExceptT getRespHeaders
247247 case res of
248248 Left e -> assertFailure $ show e
249249 Right val -> getHeaders val `shouldBe` [("X-Example1", "1729"), ("X-Example2", "eg2")]
@@ -252,7 +252,7 @@ spec = withServer $ \ baseUrl -> do
252252 it "works for a combination of Capture, QueryParam, QueryFlag and ReqBody" $
253253 property $ forAllShrink pathGen shrink $ \(NonEmpty cap) num flag body ->
254254 ioProperty $ do
255− result <- Arrow.left show <$> runEitherT (getMultiple cap num flag body)
255+ result <- left show <$> runExceptT (getMultiple cap num flag body)
256256 return $
257257 result === Right (cap, num, flag, body)
258258
@@ -261,11 +261,11 @@ spec = withServer $ \ baseUrl -> do
261261 let test :: (WrappedApi, String) -> Spec
262262 test (WrappedApi api, desc) =
263263 it desc $
264− withWaiDaemon (return (serve api (left $ ServantErr 500 "error message" "" []))) $
264+ withWaiDaemon (return (serve api (throwE $ ServantErr 500 "error message" "" []))) $
265265 \ host -> do
266− let getResponse :: EitherT ServantError IO ()
266+ let getResponse :: ExceptT ServantError IO ()
267267 getResponse = client api host
268− Left FailureResponse{..} <- runEitherT getResponse
268+ Left FailureResponse{..} <- runExceptT getResponse
269269 responseStatus `shouldBe` (Status 500 "error message")
270270 mapM_ test $
271271 (WrappedApi (Proxy :: Proxy (Delete '[JSON] ())), "Delete") :
@@ -276,54 +276,54 @@ spec = withServer $ \ baseUrl -> do
276276
277277failSpec :: IO ()
278278failSpec = withFailServer $ \ baseUrl -> do
279− let getGet :: EitherT ServantError IO Person
280− getDeleteEmpty :: EitherT ServantError IO ()
281− getCapture :: String -> EitherT ServantError IO Person
282− getBody :: Person -> EitherT ServantError IO Person
279+ let getGet :: ExceptT ServantError IO Person
280+ getDeleteEmpty :: ExceptT ServantError IO ()
281+ getCapture :: String -> ExceptT ServantError IO Person
282+ getBody :: Person -> ExceptT ServantError IO Person
283283 ( getGet
284284 :<|> getDeleteEmpty
285285 :<|> getCapture
286286 :<|> getBody
287287 :<|> _ )
288288 = client api baseUrl
289− getGetWrongHost :: EitherT ServantError IO Person
289+ getGetWrongHost :: ExceptT ServantError IO Person
290290 (getGetWrongHost :<|> _) = client api (BaseUrl Http "127.0.0.1" 19872 "")
291291
292292 hspec $ do
293293 context "client returns errors appropriately" $ do
294294 it "reports FailureResponse" $ do
295− Left res <- runEitherT getDeleteEmpty
295+ Left res <- runExceptT getDeleteEmpty
296296 case res of
297297 FailureResponse (Status 404 "Not Found") _ _ -> return ()
298298 _ -> fail $ "expected 404 response, but got " <> show res
299299
300300 it "reports DecodeFailure" $ do
301− Left res <- runEitherT (getCapture "foo")
301+ Left res <- runExceptT (getCapture "foo")
302302 case res of
303303 DecodeFailure _ ("application/json") _ -> return ()
304304 _ -> fail $ "expected DecodeFailure, but got " <> show res
305305
306306 it "reports ConnectionError" $ do
307− Left res <- runEitherT getGetWrongHost
307+ Left res <- runExceptT getGetWrongHost
308308 case res of
309309 ConnectionError _ -> return ()
310310 _ -> fail $ "expected ConnectionError, but got " <> show res
311311
312312 it "reports UnsupportedContentType" $ do
313− Left res <- runEitherT getGet
313+ Left res <- runExceptT getGet
314314 case res of
315315 UnsupportedContentType ("application/octet-stream") _ -> return ()
316316 _ -> fail $ "expected UnsupportedContentType, but got " <> show res
317317
318318 it "reports InvalidContentTypeHeader" $ do
319− Left res <- runEitherT (getBody alice)
319+ Left res <- runExceptT (getBody alice)
320320 case res of
321321 InvalidContentTypeHeader "fooooo" _ -> return ()
322322 _ -> fail $ "expected InvalidContentTypeHeader, but got " <> show res
323323
324324data WrappedApi where
325− WrappedApi :: (HasServer api, Server api ~ EitherT ServantErr IO a,
326− HasClient api, Client api ~ EitherT ServantError IO ()) =>
325+ WrappedApi :: (HasServer api, Server api ~ ExceptT ServantErr IO a,
326+ HasClient api, Client api ~ ExceptT ServantError IO ()) =>
327327 Proxy api -> WrappedApi
328328
329329
servant-examples/hackage/hackage.hs+5−5
@@ -5,7 +5,7 @@
55import Control.Applicative
66import Control.Monad
77import Control.Monad.IO.Class
8−import Control.Monad.Trans.Either
8+import Control.Monad.Trans.Except
99import Data.Aeson
1010import Data.Monoid
1111import Data.Proxy
@@ -54,16 +54,16 @@ instance FromJSON Package
5454hackageAPI :: Proxy HackageAPI
5555hackageAPI = Proxy
5656
57−getUsers :: EitherT ServantError IO [UserSummary]
58−getUser :: Username -> EitherT ServantError IO UserDetailed
59−getPackages :: EitherT ServantError IO [Package]
57+getUsers :: ExceptT ServantError IO [UserSummary]
58+getUser :: Username -> ExceptT ServantError IO UserDetailed
59+getPackages :: ExceptT ServantError IO [Package]
6060getUsers :<|> getUser :<|> getPackages = client hackageAPI $ BaseUrl Http "hackage.haskell.org" 80 ""
6161
6262main :: IO ()
6363main = print =<< uselessNumbers
6464
6565uselessNumbers :: IO (Either ServantError ())
66−uselessNumbers = runEitherT $ do
66+uselessNumbers = runExceptT $ do
6767 users <- getUsers
6868 liftIO . putStrLn $ show (length users) ++ " users"
6969
servant-examples/servant-examples.cabal+1−3
@@ -25,7 +25,6 @@ executable tutorial
2525 , base >= 4.7 && < 5
2626 , bytestring
2727 , directory
28− , either
2928 , http-types
3029 , js-jquery
3130 , lucid
@@ -50,10 +49,10 @@ executable t8-main
5049 build-depends:
5150 aeson
5251 , base >= 4.7 && < 5
53− , either
5452 , servant == 0.5.*
5553 , servant-client == 0.5.*
5654 , servant-server == 0.5.*
55+ , transformers
5756 , wai
5857
5958executable hackage
@@ -61,7 +60,6 @@ executable hackage
6160 build-depends:
6261 aeson >= 0.8
6362 , base >=4.7 && < 5
64− , either
6563 , servant == 0.5.*
6664 , servant-client == 0.5.*
6765 , text
servant-examples/tutorial/T3.hs+4−4
@@ -4,7 +4,7 @@
44{-# LANGUAGE TypeOperators #-}
55module T3 where
66
7−import Control.Monad.Trans.Either
7+import Control.Monad.Trans.Except
88import Data.Aeson
99import Data.List
1010import GHC.Generics
@@ -69,15 +69,15 @@ server = position
6969 :<|> hello
7070 :<|> marketing
7171
72− where position :: Int -> Int -> EitherT ServantErr IO Position
72+ where position :: Int -> Int -> ExceptT ServantErr IO Position
7373 position x y = return (Position x y)
7474
75− hello :: Maybe String -> EitherT ServantErr IO HelloMessage
75+ hello :: Maybe String -> ExceptT ServantErr IO HelloMessage
7676 hello mname = return . HelloMessage $ case mname of
7777 Nothing -> "Hello, anonymous coward"
7878 Just n -> "Hello, " ++ n
7979
80− marketing :: ClientInfo -> EitherT ServantErr IO Email
80+ marketing :: ClientInfo -> ExceptT ServantErr IO Email
8181 marketing clientinfo = return (emailForClient clientinfo)
8282
8383app :: Application
servant-examples/tutorial/T5.hs+2−2
@@ -6,7 +6,7 @@
66module T5 where
77
88import Control.Monad.IO.Class
9−import Control.Monad.Trans.Either
9+import Control.Monad.Trans.Except
1010import Data.Aeson
1111import GHC.Generics
1212import Network.Wai
@@ -29,7 +29,7 @@ server = do
2929 exists <- liftIO (doesFileExist "myfile.txt")
3030 if exists
3131 then liftIO (readFile "myfile.txt") >>= return . FileContent
32− else left custom404Err
32+ else throwE custom404Err
3333
3434 where custom404Err = err404 { errBody = "myfile.txt just isn't there, please leave this server alone." }
3535
servant-examples/tutorial/T7.hs+2−2
@@ -3,7 +3,7 @@
33{-# LANGUAGE TypeOperators #-}
44module T7 where
55
6−import Control.Monad.Trans.Either
6+import Control.Monad.Trans.Except
77import Control.Monad.Trans.Reader
88import Network.Wai
99import Servant
@@ -26,7 +26,7 @@ readerServerT = a :<|> b
2626readerServer :: Server ReaderAPI
2727readerServer = enter readerToEither readerServerT
2828
29− where readerToEither :: Reader String :~> EitherT ServantErr IO
29+ where readerToEither :: Reader String :~> ExceptT ServantErr IO
3030 readerToEither = Nat $ \r -> return (runReader r "hi")
3131
3232app :: Application
servant-examples/tutorial/T8.hs+6−6
@@ -3,7 +3,7 @@
33{-# LANGUAGE TypeOperators #-}
44module T8 where
55
6−import Control.Monad.Trans.Either
6+import Control.Monad.Trans.Except
77import Data.Aeson
88import Servant
99import Servant.Client
@@ -12,20 +12,20 @@ import T3
1212
1313position :: Int -- ^ value for "x"
1414 -> Int -- ^ value for "y"
15− -> EitherT ServantError IO Position
15+ -> ExceptT ServantError IO Position
1616
1717hello :: Maybe String -- ^ an optional value for "name"
18− -> EitherT ServantError IO HelloMessage
18+ -> ExceptT ServantError IO HelloMessage
1919
2020marketing :: ClientInfo -- ^ value for the request body
21− -> EitherT ServantError IO Email
21+ -> ExceptT ServantError IO Email
2222
2323position :<|> hello :<|> marketing = client api baseUrl
2424
2525baseUrl :: BaseUrl
2626baseUrl = BaseUrl Http "localhost" 8081 ""
2727
28−queries :: EitherT ServantError IO (Position, HelloMessage, Email)
28+queries :: ExceptT ServantError IO (Position, HelloMessage, Email)
2929queries = do
3030 pos <- position 10 10
3131 msg <- hello (Just "servant")
@@ -34,7 +34,7 @@ queries = do
3434
3535run :: IO ()
3636run = do
37− res <- runEitherT queries
37+ res <- runExceptT queries
3838 case res of
3939 Left err -> putStrLn $ "Error: " ++ show err
4040 Right (pos, msg, em) -> do
servant-mock/src/Servant/Mock.hs+2−2
@@ -91,8 +91,8 @@ class HasServer api => HasMock api where
9191 -- actually "means" 2 request handlers, of the following types:
9292 --
9393 -- @
94− -- getUser :: EitherT ServantErr IO User
95− -- getBook :: EitherT ServantErr IO Book
94+ -- getUser :: ExceptT ServantErr IO User
95+ -- getBook :: ExceptT ServantErr IO Book
9696 -- @
9797 --
9898 -- So under the hood, 'mock' uses the 'IO' bit to generate
servant-server/CHANGELOG.md+1
@@ -2,6 +2,7 @@ HEAD
22----
33
44* Support for the `HttpVersion`, `IsSecure`, `RemoteHost` and `Vault` combinators
5+* Drop `EitherT` in favor of `ExceptT`
56
670.4.1
78-----
servant-server/example/greet.hs+1−1
@@ -44,7 +44,7 @@ testApi = Proxy
4444-- There's one handler per endpoint, which, just like in the type
4545-- that represents the API, are glued together using :<|>.
4646--
47−-- Each handler runs in the 'EitherT ServantErr IO' monad.
47+-- Each handler runs in the 'ExceptT ServantErr IO' monad.
4848server :: Server TestApi
4949server = helloH :<|> postGreetH :<|> deleteGreetH
5050
servant-server/servant-server.cabal−2
@@ -48,7 +48,6 @@ library
4848 , attoparsec >= 0.12 && < 0.14
4949 , bytestring >= 0.10 && < 0.11
5050 , containers >= 0.5 && < 0.6
51− , either >= 4.3 && < 4.5
5251 , http-types >= 0.8 && < 0.9
5352 , network-uri >= 2.6 && < 2.7
5453 , mtl >= 2 && < 3
@@ -97,7 +96,6 @@ test-suite spec
9796 , bytestring
9897 , bytestring-conversion
9998 , directory
100− , either
10199 , exceptions
102100 , hspec == 2.*
103101 , hspec-wai
servant-server/src/Servant/Server.hs+1−5
@@ -1,4 +1,3 @@
1−{-# LANGUAGE CPP #-}
21{-# LANGUAGE FlexibleContexts #-}
32{-# LANGUAGE OverloadedStrings #-}
43{-# LANGUAGE TypeFamilies #-}
@@ -29,9 +28,6 @@ module Servant.Server
2928 , evalStateTSNat
3029 , logWriterTLNat
3130 , logWriterTSNat
32−#if MIN_VERSION_mtl(2,2,1)
33− , fromExceptT
34−#endif
3531 -- ** Functions based on <https://hackage.haskell.org/package/mmorph mmorph>
3632 , hoistNat
3733 , embedNat
@@ -113,7 +109,7 @@ serve p server = toApplication (runRouter (route p (return (RR (Right server))))
113109-- Documentation
114110
115111-- $enterDoc
116−-- Sometimes our cherished `EitherT` monad isn't quite the type you'd like for
112+-- Sometimes our cherished `ExceptT` monad isn't quite the type you'd like for
117113-- your handlers. Maybe you want to thread some configuration in a @Reader@
118114-- monad. Or have your types ensure that your handlers don't do any IO. Enter
119115-- `enter`.
servant-server/src/Servant/Server/Internal.hs+24−24
@@ -23,7 +23,7 @@ module Servant.Server.Internal
2323#if !MIN_VERSION_base(4,8,0)
2424import Control.Applicative ((<$>))
2525#endif
26−import Control.Monad.Trans.Either (EitherT)
26+import Control.Monad.Trans.Except (ExceptT)
2727import qualified Data.ByteString as B
2828import qualified Data.ByteString.Lazy as BL
2929import qualified Data.Map as M
@@ -65,7 +65,7 @@ class HasServer layout where
6565
6666 route :: Proxy layout -> IO (RouteResult (Server layout)) -> Router
6767
68−type Server layout = ServerT layout (EitherT ServantErr IO)
68+type Server layout = ServerT layout (ExceptT ServantErr IO)
6969
7070-- * Instances
7171
@@ -107,7 +107,7 @@ captured _ = fromText
107107-- >
108108-- > server :: Server MyApi
109109-- > server = getBook
110−-- > where getBook :: Text -> EitherT ServantErr IO Book
110+-- > where getBook :: Text -> ExceptT ServantErr IO Book
111111-- > getBook isbn = ...
112112instance (KnownSymbol capture, FromText a, HasServer sublayout)
113113 => HasServer (Capture capture a :> sublayout) where
@@ -142,7 +142,7 @@ processMethodRouter handleA status method headers request = case handleA of
142142
143143methodRouter :: (AllCTRender ctypes a)
144144 => Method -> Proxy ctypes -> Status
145− -> IO (RouteResult (EitherT ServantErr IO a))
145+ -> IO (RouteResult (ExceptT ServantErr IO a))
146146 -> Router
147147methodRouter method proxy status action = LeafRouter route'
148148 where
@@ -158,7 +158,7 @@ methodRouter method proxy status action = LeafRouter route'
158158
159159methodRouterHeaders :: (GetHeaders (Headers h v), AllCTRender ctypes v)
160160 => Method -> Proxy ctypes -> Status
161− -> IO (RouteResult (EitherT ServantErr IO (Headers h v)))
161+ -> IO (RouteResult (ExceptT ServantErr IO (Headers h v)))
162162 -> Router
163163methodRouterHeaders method proxy status action = LeafRouter route'
164164 where
@@ -174,7 +174,7 @@ methodRouterHeaders method proxy status action = LeafRouter route'
174174 | otherwise = respond $ failWith NotFound
175175
176176methodRouterEmpty :: Method
177− -> IO (RouteResult (EitherT ServantErr IO ()))
177+ -> IO (RouteResult (ExceptT ServantErr IO ()))
178178 -> Router
179179methodRouterEmpty method action = LeafRouter route'
180180 where
@@ -192,9 +192,9 @@ methodRouterEmpty method action = LeafRouter route'
192192--
193193-- The code of the handler will, just like
194194-- for 'Servant.API.Get.Get', 'Servant.API.Post.Post' and
195−-- 'Servant.API.Put.Put', run in @EitherT ServantErr IO ()@.
195+-- 'Servant.API.Put.Put', run in @ExceptT ServantErr IO ()@.
196196-- The 'Int' represents the status code and the 'String' a message
197−-- to be returned. You can use 'Control.Monad.Trans.Either.left' to
197+-- to be returned. You can use 'Control.Monad.Trans.Except.throwE' to
198198-- painlessly error out if the conditions for a successful deletion
199199-- are not met.
200200instance
@@ -233,9 +233,9 @@ instance
233233-- | When implementing the handler for a 'Get' endpoint,
234234-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Post.Post'
235235-- and 'Servant.API.Put.Put', the handler code runs in the
236−-- @EitherT ServantErr IO@ monad, where the 'Int' represents
236+-- @ExceptT ServantErr IO@ monad, where the 'Int' represents
237237-- the status code and the 'String' a message, returned in case of
238−-- failure. You can quite handily use 'Control.Monad.Trans.EitherT.left'
238+-- failure. You can quite handily use 'Control.Monad.Trans.Except.throwE'
239239-- to quickly fail if some conditions are not met.
240240--
241241-- If successfully returning a value, we use the type-level list, combined
@@ -294,7 +294,7 @@ instance
294294-- >
295295-- > server :: Server MyApi
296296-- > server = viewReferer
297−-- > where viewReferer :: Referer -> EitherT ServantErr IO referer
297+-- > where viewReferer :: Referer -> ExceptT ServantErr IO referer
298298-- > viewReferer referer = return referer
299299instance (KnownSymbol sym, FromText a, HasServer sublayout)
300300 => HasServer (Header sym a :> sublayout) where
@@ -310,9 +310,9 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
310310-- | When implementing the handler for a 'Post' endpoint,
311311-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Get.Get'
312312-- and 'Servant.API.Put.Put', the handler code runs in the
313−-- @EitherT ServantErr IO@ monad, where the 'Int' represents
313+-- @ExceptT ServantErr IO@ monad, where the 'Int' represents
314314-- the status code and the 'String' a message, returned in case of
315−-- failure. You can quite handily use 'Control.Monad.Trans.EitherT.left'
315+-- failure. You can quite handily use 'Control.Monad.Trans.Except.throwE'
316316-- to quickly fail if some conditions are not met.
317317--
318318-- If successfully returning a value, we use the type-level list, combined
@@ -356,9 +356,9 @@ instance
356356-- | When implementing the handler for a 'Put' endpoint,
357357-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Get.Get'
358358-- and 'Servant.API.Post.Post', the handler code runs in the
359−-- @EitherT ServantErr IO@ monad, where the 'Int' represents
359+-- @ExceptT ServantErr IO@ monad, where the 'Int' represents
360360-- the status code and the 'String' a message, returned in case of
361−-- failure. You can quite handily use 'Control.Monad.Trans.EitherT.left'
361+-- failure. You can quite handily use 'Control.Monad.Trans.Except.throwE'
362362-- to quickly fail if some conditions are not met.
363363--
364364-- If successfully returning a value, we use the type-level list, combined
@@ -401,9 +401,9 @@ instance
401401-- | When implementing the handler for a 'Patch' endpoint,
402402-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Get.Get'
403403-- and 'Servant.API.Put.Put', the handler code runs in the
404−-- @EitherT ServantErr IO@ monad, where the 'Int' represents
404+-- @ExceptT ServantErr IO@ monad, where the 'Int' represents
405405-- the status code and the 'String' a message, returned in case of
406−-- failure. You can quite handily use 'Control.Monad.Trans.EitherT.left'
406+-- failure. You can quite handily use 'Control.Monad.Trans.Except.throwE'
407407-- to quickly fail if some conditions are not met.
408408--
409409-- If successfully returning a value, we just require that its type has
@@ -459,7 +459,7 @@ instance
459459-- >
460460-- > server :: Server MyApi
461461-- > server = getBooksBy
462−-- > where getBooksBy :: Maybe Text -> EitherT ServantErr IO [Book]
462+-- > where getBooksBy :: Maybe Text -> ExceptT ServantErr IO [Book]
463463-- > getBooksBy Nothing = ...return all books...
464464-- > getBooksBy (Just author) = ...return books by the given author...
465465instance (KnownSymbol sym, FromText a, HasServer sublayout)
@@ -496,7 +496,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
496496-- >
497497-- > server :: Server MyApi
498498-- > server = getBooksBy
499−-- > where getBooksBy :: [Text] -> EitherT ServantErr IO [Book]
499+-- > where getBooksBy :: [Text] -> ExceptT ServantErr IO [Book]
500500-- > getBooksBy authors = ...return all books by these authors...
501501instance (KnownSymbol sym, FromText a, HasServer sublayout)
502502 => HasServer (QueryParams sym a :> sublayout) where
@@ -527,7 +527,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
527527-- >
528528-- > server :: Server MyApi
529529-- > server = getBooks
530−-- > where getBooks :: Bool -> EitherT ServantErr IO [Book]
530+-- > where getBooks :: Bool -> ExceptT ServantErr IO [Book]
531531-- > getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
532532instance (KnownSymbol sym, HasServer sublayout)
533533 => HasServer (QueryFlag sym :> sublayout) where
@@ -567,7 +567,7 @@ parseMatrixText = parseQueryText
567567-- >
568568-- > server :: Server MyApi
569569-- > server = getBooksBy
570−-- > where getBooksBy :: Maybe Text -> EitherT ServantErr IO [Book]
570+-- > where getBooksBy :: Maybe Text -> ExceptT ServantErr IO [Book]
571571-- > getBooksBy Nothing = ...return all books...
572572-- > getBooksBy (Just author) = ...return books by the given author...
573573instance (KnownSymbol sym, FromText a, HasServer sublayout)
@@ -607,7 +607,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
607607-- >
608608-- > server :: Server MyApi
609609-- > server = getBooksBy
610−-- > where getBooksBy :: [Text] -> EitherT ServantErr IO [Book]
610+-- > where getBooksBy :: [Text] -> ExceptT ServantErr IO [Book]
611611-- > getBooksBy authors = ...return all books by these authors...
612612instance (KnownSymbol sym, FromText a, HasServer sublayout)
613613 => HasServer (MatrixParams sym a :> sublayout) where
@@ -641,7 +641,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
641641-- >
642642-- > server :: Server MyApi
643643-- > server = getBooks
644−-- > where getBooks :: Bool -> EitherT ServantErr IO [Book]
644+-- > where getBooks :: Bool -> ExceptT ServantErr IO [Book]
645645-- > getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
646646instance (KnownSymbol sym, HasServer sublayout)
647647 => HasServer (MatrixFlag sym :> sublayout) where
@@ -699,7 +699,7 @@ instance HasServer Raw where
699699-- >
700700-- > server :: Server MyApi
701701-- > server = postBook
702−-- > where postBook :: Book -> EitherT ServantErr IO Book
702+-- > where postBook :: Book -> ExceptT ServantErr IO Book
703703-- > postBook book = ...insert into your db...
704704instance ( AllCTUnrender list a, HasServer sublayout
705705 ) => HasServer (ReqBody list a :> sublayout) where
servant-server/src/Servant/Server/Internal/Enter.hs−8
@@ -22,9 +22,6 @@ import Control.Monad.Morph
2222import Control.Monad.Reader
2323import qualified Control.Monad.State.Lazy as LState
2424import qualified Control.Monad.State.Strict as SState
25−#if MIN_VERSION_mtl(2,2,1)
26−import Control.Monad.Trans.Either
27−#endif
2825import qualified Control.Monad.Writer.Lazy as LWriter
2926import qualified Control.Monad.Writer.Strict as SWriter
3027import Data.Typeable
@@ -83,11 +80,6 @@ logWriterTLNat logger = Nat $ \x -> do
8380 liftIO $ logger w
8481 return a
8582
86−#if MIN_VERSION_mtl(2,2,1)
87−fromExceptT :: ExceptT e m :~> EitherT e m
88−fromExceptT = Nat $ \x -> EitherT $ runExceptT x
89−#endif
90−
9183-- | Like @mmorph@'s `hoist`.
9284hoistNat :: (MFunctor t, Monad m) => (m :~> n) -> (t m :~> t n)
9385hoistNat (Nat n) = Nat $ hoist n
servant-server/src/Servant/Server/Internal/RoutingApplication.hs+3−3
@@ -8,7 +8,7 @@ module Servant.Server.Internal.RoutingApplication where
88import Control.Applicative (Applicative, (<$>))
99import Data.Monoid (Monoid, mappend, mempty)
1010#endif
11−import Control.Monad.Trans.Either (EitherT, runEitherT)
11+import Control.Monad.Trans.Except (ExceptT, runExceptT)
1212import qualified Data.ByteString as B
1313import qualified Data.ByteString.Lazy as BL
1414import Data.IORef (newIORef, readIORef,
@@ -107,7 +107,7 @@ toApplication ra request respond = do
107107 routingRespond (Right response) =
108108 respond response
109109
110−runAction :: IO (RouteResult (EitherT ServantErr IO a))
110+runAction :: IO (RouteResult (ExceptT ServantErr IO a))
111111 -> (RouteResult Response -> IO r)
112112 -> (a -> RouteResult Response)
113113 -> IO r
@@ -116,7 +116,7 @@ runAction action respond k = do
116116 go r
117117 where
118118 go (RR (Right a)) = do
119− e <- runEitherT a
119+ e <- runExceptT a
120120 respond $ case e of
121121 Right x -> k x
122122 Left err -> succeedWith $ responseServantErr err
servant-server/test/Servant/Server/Internal/EnterSpec.hs+2−2
@@ -5,7 +5,7 @@ module Servant.Server.Internal.EnterSpec where
55
66import qualified Control.Category as C
77import Control.Monad.Reader
8−import Control.Monad.Trans.Either
8+import Control.Monad.Trans.Except
99import Data.Proxy
1010import Servant.API
1111import Servant.Server
@@ -34,7 +34,7 @@ combinedAPI = Proxy
3434readerServer' :: ServerT ReaderAPI (Reader String)
3535readerServer' = return 1797 :<|> ask
3636
37−fReader :: Reader String :~> EitherT ServantErr IO
37+fReader :: Reader String :~> ExceptT ServantErr IO
3838fReader = generalizeNat C.. (runReaderTNat "hi")
3939
4040readerServer :: Server ReaderAPI
servant-server/test/Servant/ServerSpec.hs+5−5
@@ -10,7 +10,7 @@ module Servant.ServerSpec where
1010
1111
1212import Control.Monad (forM_, when)
13−import Control.Monad.Trans.Either (EitherT, left)
13+import Control.Monad.Trans.Except (ExceptT, throwE)
1414import Data.Aeson (FromJSON, ToJSON, decode', encode)
1515import Data.ByteString.Conversion ()
1616import Data.Char (toUpper)
@@ -99,11 +99,11 @@ spec = do
9999type CaptureApi = Capture "legs" Integer :> Get '[JSON] Animal
100100captureApi :: Proxy CaptureApi
101101captureApi = Proxy
102−captureServer :: Integer -> EitherT ServantErr IO Animal
102+captureServer :: Integer -> ExceptT ServantErr IO Animal
103103captureServer legs = case legs of
104104 4 -> return jerry
105105 2 -> return tweety
106− _ -> left err404
106+ _ -> throwE err404
107107
108108captureSpec :: Spec
109109captureSpec = do
@@ -481,11 +481,11 @@ headerApi = Proxy
481481headerSpec :: Spec
482482headerSpec = describe "Servant.API.Header" $ do
483483
484− let expectsInt :: Maybe Int -> EitherT ServantErr IO ()
484+ let expectsInt :: Maybe Int -> ExceptT ServantErr IO ()
485485 expectsInt (Just x) = when (x /= 5) $ error "Expected 5"
486486 expectsInt Nothing = error "Expected an int"
487487
488− let expectsString :: Maybe String -> EitherT ServantErr IO ()
488+ let expectsString :: Maybe String -> ExceptT ServantErr IO ()
489489 expectsString (Just x) = when (x /= "more from you") $ error "Expected more from you"
490490 expectsString Nothing = error "Expected a string"
491491
stack.yaml+1−1
@@ -14,4 +14,4 @@ packages:
1414- servant-server/
1515extra-deps:
1616- engine-io-wai-1.0.2
17−resolver: nightly-2015-09-05
17+resolver: nightly-2015-09-10