Skip to content

Commit 3db3d38

Browse files
authored
Merge pull request #1131 from phadej/error-renaming
Rename ServantError to ClientError, ServantErr to ServerError
2 parents e922b98 + a5655f8 commit 3db3d38

File tree

25 files changed

+162
-166
lines changed

25 files changed

+162
-166
lines changed

.travis.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ install:
8787
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"doc/cookbook/db-sqlite-simple\"\\n' >> cabal.project ; fi"
8888
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"doc/cookbook/file-upload\"\\n' >> cabal.project ; fi"
8989
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"doc/cookbook/generic\"\\n' >> cabal.project ; fi"
90-
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"doc/cookbook/hoist-server-with-context\"\\n' >> cabal.project ; fi"
9190
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"doc/cookbook/https\"\\n' >> cabal.project ; fi"
92-
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"doc/cookbook/jwt-and-basic-auth\"\\n' >> cabal.project ; fi"
9391
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"doc/cookbook/testing\"\\n' >> cabal.project ; fi"
9492
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"doc/cookbook/structuring-apis\"\\n' >> cabal.project ; fi"
9593
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"doc/cookbook/using-custom-monad\"\\n' >> cabal.project ; fi"
@@ -106,7 +104,7 @@ install:
106104
- "echo 'reorder-goals: True' >> cabal.project"
107105
- "echo 'optimization: False' >> cabal.project "
108106
- touch cabal.project.local
109-
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(cookbook-basic-auth|cookbook-basic-streaming|cookbook-curl-mock|cookbook-db-postgres-pool|cookbook-db-sqlite-simple|cookbook-file-upload|cookbook-generic|cookbook-hoist-server-with-context|cookbook-https|cookbook-jwt-and-basic-auth|cookbook-structuring-apis|cookbook-testing|cookbook-using-custom-monad|cookbook-using-free-client|servant|servant-client|servant-client-core|servant-conduit|servant-docs|servant-foreign|servant-http-streams|servant-machines|servant-pipes|servant-server|tutorial)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
107+
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(cookbook-basic-auth|cookbook-basic-streaming|cookbook-curl-mock|cookbook-db-postgres-pool|cookbook-db-sqlite-simple|cookbook-file-upload|cookbook-generic|cookbook-https|cookbook-structuring-apis|cookbook-testing|cookbook-using-custom-monad|cookbook-using-free-client|servant|servant-client|servant-client-core|servant-conduit|servant-docs|servant-foreign|servant-http-streams|servant-machines|servant-pipes|servant-server|tutorial)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
110108
- cat cabal.project || true
111109
- cat cabal.project.local || true
112110
- if [ -f "servant/configure.ac" ]; then (cd "servant" && autoreconf -i); fi
@@ -127,15 +125,13 @@ install:
127125
- if [ -f "doc/cookbook/db-sqlite-simple/configure.ac" ]; then (cd "doc/cookbook/db-sqlite-simple" && autoreconf -i); fi
128126
- if [ -f "doc/cookbook/file-upload/configure.ac" ]; then (cd "doc/cookbook/file-upload" && autoreconf -i); fi
129127
- if [ -f "doc/cookbook/generic/configure.ac" ]; then (cd "doc/cookbook/generic" && autoreconf -i); fi
130-
- if [ -f "doc/cookbook/hoist-server-with-context/configure.ac" ]; then (cd "doc/cookbook/hoist-server-with-context" && autoreconf -i); fi
131128
- if [ -f "doc/cookbook/https/configure.ac" ]; then (cd "doc/cookbook/https" && autoreconf -i); fi
132-
- if [ -f "doc/cookbook/jwt-and-basic-auth/configure.ac" ]; then (cd "doc/cookbook/jwt-and-basic-auth" && autoreconf -i); fi
133129
- if [ -f "doc/cookbook/testing/configure.ac" ]; then (cd "doc/cookbook/testing" && autoreconf -i); fi
134130
- if [ -f "doc/cookbook/structuring-apis/configure.ac" ]; then (cd "doc/cookbook/structuring-apis" && autoreconf -i); fi
135131
- if [ -f "doc/cookbook/using-custom-monad/configure.ac" ]; then (cd "doc/cookbook/using-custom-monad" && autoreconf -i); fi
136132
- if [ -f "doc/cookbook/using-free-client/configure.ac" ]; then (cd "doc/cookbook/using-free-client" && autoreconf -i); fi
137133
- rm -f cabal.project.freeze
138-
- rm -rf .ghc.environment.* "servant"/dist "servant-client"/dist "servant-client-core"/dist "servant-http-streams"/dist "servant-docs"/dist "servant-foreign"/dist "servant-server"/dist "doc/tutorial"/dist "servant-machines"/dist "servant-conduit"/dist "servant-pipes"/dist "doc/cookbook/basic-auth"/dist "doc/cookbook/curl-mock"/dist "doc/cookbook/basic-streaming"/dist "doc/cookbook/db-postgres-pool"/dist "doc/cookbook/db-sqlite-simple"/dist "doc/cookbook/file-upload"/dist "doc/cookbook/generic"/dist "doc/cookbook/hoist-server-with-context"/dist "doc/cookbook/https"/dist "doc/cookbook/jwt-and-basic-auth"/dist "doc/cookbook/testing"/dist "doc/cookbook/structuring-apis"/dist "doc/cookbook/using-custom-monad"/dist "doc/cookbook/using-free-client"/dist
134+
- rm -rf .ghc.environment.* "servant"/dist "servant-client"/dist "servant-client-core"/dist "servant-http-streams"/dist "servant-docs"/dist "servant-foreign"/dist "servant-server"/dist "doc/tutorial"/dist "servant-machines"/dist "servant-conduit"/dist "servant-pipes"/dist "doc/cookbook/basic-auth"/dist "doc/cookbook/curl-mock"/dist "doc/cookbook/basic-streaming"/dist "doc/cookbook/db-postgres-pool"/dist "doc/cookbook/db-sqlite-simple"/dist "doc/cookbook/file-upload"/dist "doc/cookbook/generic"/dist "doc/cookbook/https"/dist "doc/cookbook/testing"/dist "doc/cookbook/structuring-apis"/dist "doc/cookbook/using-custom-monad"/dist "doc/cookbook/using-free-client"/dist
139135
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
140136

141137
# Here starts the actual work to be performed for the package under test;
@@ -169,9 +165,7 @@ script:
169165
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"cookbook-db-sqlite-simple-*/*.cabal\"\\n' >> cabal.project ; fi"
170166
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"cookbook-file-upload-*/*.cabal\"\\n' >> cabal.project ; fi"
171167
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"cookbook-generic-*/*.cabal\"\\n' >> cabal.project ; fi"
172-
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"cookbook-hoist-server-with-context-*/*.cabal\"\\n' >> cabal.project ; fi"
173168
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"cookbook-https-*/*.cabal\"\\n' >> cabal.project ; fi"
174-
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"cookbook-jwt-and-basic-auth-*/*.cabal\"\\n' >> cabal.project ; fi"
175169
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"cookbook-testing-*/*.cabal\"\\n' >> cabal.project ; fi"
176170
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"cookbook-structuring-apis-*/*.cabal\"\\n' >> cabal.project ; fi"
177171
- "if [ $HCNUMVER -eq 80404 ] || [ $HCNUMVER -eq 80603 ] ; then printf 'packages: \"cookbook-using-custom-monad-*/*.cabal\"\\n' >> cabal.project ; fi"
@@ -188,7 +182,7 @@ script:
188182
- "echo 'reorder-goals: True' >> cabal.project"
189183
- "echo 'optimization: False' >> cabal.project "
190184
- touch cabal.project.local
191-
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(cookbook-basic-auth|cookbook-basic-streaming|cookbook-curl-mock|cookbook-db-postgres-pool|cookbook-db-sqlite-simple|cookbook-file-upload|cookbook-generic|cookbook-hoist-server-with-context|cookbook-https|cookbook-jwt-and-basic-auth|cookbook-structuring-apis|cookbook-testing|cookbook-using-custom-monad|cookbook-using-free-client|servant|servant-client|servant-client-core|servant-conduit|servant-docs|servant-foreign|servant-http-streams|servant-machines|servant-pipes|servant-server|tutorial)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
185+
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(cookbook-basic-auth|cookbook-basic-streaming|cookbook-curl-mock|cookbook-db-postgres-pool|cookbook-db-sqlite-simple|cookbook-file-upload|cookbook-generic|cookbook-https|cookbook-structuring-apis|cookbook-testing|cookbook-using-custom-monad|cookbook-using-free-client|servant|servant-client|servant-client-core|servant-conduit|servant-docs|servant-foreign|servant-http-streams|servant-machines|servant-pipes|servant-server|tutorial)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
192186
- cat cabal.project || true
193187
- cat cabal.project.local || true
194188
- echo -en 'travis_fold:end:unpack\\r'

cabal.project

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ packages:
2121
doc/cookbook/db-sqlite-simple
2222
doc/cookbook/file-upload
2323
doc/cookbook/generic
24-
doc/cookbook/hoist-server-with-context
24+
-- doc/cookbook/hoist-server-with-context
2525
doc/cookbook/https
26-
doc/cookbook/jwt-and-basic-auth/
26+
-- doc/cookbook/jwt-and-basic-auth/
2727
-- doc/cookbook/pagination
28-
-- doc/cookbook/sentry
28+
-- doc/cookbook/sentry
2929
doc/cookbook/testing
3030
doc/cookbook/structuring-apis
3131
doc/cookbook/using-custom-monad

doc/cookbook/testing/Testing.lhs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ clientEnv esHost esPort = do
234234
manager <- newManager defaultManagerSettings
235235
pure $ mkClientEnv manager baseUrl
236236
237-
runSearchClient :: Text -> Text -> ClientM a -> IO (Either ServantError a)
237+
runSearchClient :: Text -> Text -> ClientM a -> IO (Either ClientError a)
238238
runSearchClient esHost esPort = (clientEnv esHost esPort >>=) . runClientM
239239
```
240240
@@ -267,7 +267,7 @@ docServer esHost esPort = getDocById esHost esPort
267267
-- actions
268268
getDocById :: Text -> Text -> Integer -> Handler Value
269269
getDocById esHost esPort docId = do
270-
-- Our Servant Client function returns Either ServantError Value here:
270+
-- Our Servant Client function returns Either ClientError Value here:
271271
docRes <- liftIO $ runSearchClient esHost esPort (getDocument docId)
272272
case docRes of
273273
Left err -> throwError $ err404 { errBody = "Failed looking up content" }

doc/tutorial/Server.lhs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ $ curl -H 'Accept: text/html' http://localhost:8081/persons
599599
600600
## The `Handler` monad
601601
602-
At the heart of the handlers is the monad they run in, namely a newtype `Handler` around `ExceptT ServantErr IO`
602+
At the heart of the handlers is the monad they run in, namely a newtype `Handler` around `ExceptT ServerErroror IO`
603603
([haddock documentation for `ExceptT`](http://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Except.html#t:ExceptT)).
604604
One might wonder: why this monad? The answer is that it is the
605605
simplest monad with the following properties:
@@ -617,7 +617,7 @@ newtype ExceptT e m a = ExceptT (m (Either e a))
617617
```
618618
619619
In short, this means that a handler of type `Handler a` is simply
620-
equivalent to a computation of type `IO (Either ServantErr a)`, that is, an IO
620+
equivalent to a computation of type `IO (Either ServerError a)`, that is, an IO
621621
action that either returns an error or a result.
622622
623623
The module [`Control.Monad.Except`](https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Except.html#t:ExceptT)
@@ -660,16 +660,16 @@ server5 = do
660660
return (FileContent filecontent)
661661
```
662662
663-
### Failing, through `ServantErr`
663+
### Failing, through `ServerError`
664664
665665
If you want to explicitly fail at providing the result promised by an endpoint
666666
using the appropriate HTTP status code (not found, unauthorized, etc) and some
667667
error message, all you have to do is use the `throwError` function mentioned above
668-
and provide it with the appropriate value of type `ServantErr`, which is
668+
and provide it with the appropriate value of type `ServerError`, which is
669669
defined as:
670670
671671
``` haskell ignore
672-
data ServantErr = ServantErr
672+
data ServerError = ServerError
673673
{ errHTTPCode :: Int
674674
, errReasonPhrase :: String
675675
, errBody :: ByteString -- lazy bytestring
@@ -685,7 +685,7 @@ use record update syntax:
685685
failingHandler :: Handler ()
686686
failingHandler = throwError myerr
687687
688-
where myerr :: ServantErr
688+
where myerr :: ServerError
689689
myerr = err503 { errBody = "Sorry dear user." }
690690
```
691691

servant-client-core/src/Servant/Client/Core.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Servant.Client.Core
3232
, AuthClientData
3333

3434
-- * Generic Client
35-
, ServantError(..)
35+
, ClientError(..)
3636
, EmptyClient(..)
3737

3838
-- * Response

servant-client-core/src/Servant/Client/Core/ClientError.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{-# LANGUAGE ScopedTypeVariables #-}
1010
{-# LANGUAGE TypeFamilies #-}
1111
module Servant.Client.Core.ClientError (
12-
ServantError (..),
12+
ClientError (..),
1313
) where
1414

1515
import Prelude ()
@@ -42,7 +42,7 @@ import Servant.Client.Core.Response
4242
-- | A type representing possible errors in a request
4343
--
4444
-- Note that this type substantially changed in 0.12.
45-
data ServantError =
45+
data ClientError =
4646
-- | The server returned an error response including the
4747
-- failing request. 'requestPath' includes the 'BaseUrl' and the
4848
-- path of the request.
@@ -57,7 +57,7 @@ data ServantError =
5757
| ConnectionError SomeException
5858
deriving (Show, Generic, Typeable)
5959

60-
instance Eq ServantError where
60+
instance Eq ClientError where
6161
FailureResponse req res == FailureResponse req' res' = req == req' && res == res'
6262
DecodeFailure t r == DecodeFailure t' r' = t == t' && r == r'
6363
UnsupportedContentType mt r == UnsupportedContentType mt' r' = mt == mt' && r == r'
@@ -74,11 +74,11 @@ instance Eq ServantError where
7474
InvalidContentTypeHeader {} == _ = False
7575
ConnectionError {} == _ = False
7676

77-
instance Exception ServantError
77+
instance Exception ClientError
7878

7979
-- | Note: an exception in 'ConnectionError' might not be evaluated fully,
8080
-- We only 'rnf' its 'show'ed value.
81-
instance NFData ServantError where
81+
instance NFData ClientError where
8282
rnf (FailureResponse req res) = rnf req `seq` rnf res
8383
rnf (DecodeFailure err res) = rnf err `seq` rnf res
8484
rnf (UnsupportedContentType mt' res) = mediaTypeRnf mt' `seq` rnf res

servant-client-core/src/Servant/Client/Core/HasClient.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ instance {-# OVERLAPPING #-}
254254
, requestAccept = fromList $ toList accept
255255
}
256256
case mimeUnrender (Proxy :: Proxy ct) $ responseBody response of
257-
Left err -> throwServantError $ DecodeFailure (pack err) response
257+
Left err -> throwClientError $ DecodeFailure (pack err) response
258258
Right val -> return $ Headers
259259
{ getResponse = val
260260
, getHeadersHList = buildHeadersTo . toList $ responseHeaders response
@@ -662,17 +662,17 @@ checkContentTypeHeader response =
662662
case lookup "Content-Type" $ toList $ responseHeaders response of
663663
Nothing -> return $ "application"//"octet-stream"
664664
Just t -> case parseAccept t of
665-
Nothing -> throwServantError $ InvalidContentTypeHeader response
665+
Nothing -> throwClientError $ InvalidContentTypeHeader response
666666
Just t' -> return t'
667667

668668
decodedAs :: forall ct a m. (MimeUnrender ct a, RunClient m)
669669
=> Response -> Proxy ct -> m a
670670
decodedAs response ct = do
671671
responseContentType <- checkContentTypeHeader response
672672
unless (any (matches responseContentType) accept) $
673-
throwServantError $ UnsupportedContentType responseContentType response
673+
throwClientError $ UnsupportedContentType responseContentType response
674674
case mimeUnrender ct $ responseBody response of
675-
Left err -> throwServantError $ DecodeFailure (T.pack err) response
675+
Left err -> throwClientError $ DecodeFailure (T.pack err) response
676676
Right val -> return val
677677
where
678678
accept = toList $ contentTypes ct

servant-client-core/src/Servant/Client/Core/Reexport.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Servant.Client.Core.Reexport
1212
, ResponseF(..)
1313

1414
-- * Data types
15-
, ServantError(..)
15+
, ClientError(..)
1616
, EmptyClient(..)
1717

1818
-- * BaseUrl

servant-client-core/src/Servant/Client/Core/RunClient.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Servant.Client.Core.Response
2424
class Monad m => RunClient m where
2525
-- | How to make a request.
2626
runRequest :: Request -> m Response
27-
throwServantError :: ServantError -> m a
27+
throwClientError :: ClientError -> m a
2828

2929
class RunClient m => RunStreamingClient m where
3030
withStreamingRequest :: Request -> (StreamingResponse -> IO a) -> m a
@@ -38,9 +38,9 @@ class RunClient m => RunStreamingClient m where
3838
-- Compare to 'RunClient'.
3939
data ClientF a
4040
= RunRequest Request (Response -> a)
41-
| Throw ServantError
41+
| Throw ClientError
4242
deriving (Functor)
4343

4444
instance ClientF ~ f => RunClient (Free f) where
4545
runRequest req = liftF (RunRequest req id)
46-
throwServantError = liftF . Throw
46+
throwClientError = liftF . Throw

servant-client-ghcjs/src/Servant/Client/Internal/XhrClient.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ client api = api `clientIn` (Proxy :: Proxy ClientM)
9494
--
9595
-- NOTE: Does not support constant space streaming of the request body!
9696
newtype ClientM a = ClientM
97-
{ runClientM' :: ReaderT ClientEnv (ExceptT ServantError IO) a }
97+
{ runClientM' :: ReaderT ClientEnv (ExceptT ClientError IO) a }
9898
deriving ( Functor, Applicative, Monad, MonadIO, Generic
99-
, MonadReader ClientEnv, MonadError ServantError, MonadThrow
99+
, MonadReader ClientEnv, MonadError ClientError, MonadThrow
100100
, MonadCatch)
101101

102102
instance MonadBase IO ClientM where
103103
liftBase = ClientM . liftBase
104104

105105
instance MonadBaseControl IO ClientM where
106-
type StM ClientM a = Either ServantError a
106+
type StM ClientM a = Either ClientError a
107107

108108
liftBaseWith f = ClientM (liftBaseWith (\g -> f (g . runClientM')))
109109

@@ -121,12 +121,12 @@ instance Exception StreamingNotSupportedException where
121121

122122
instance RunClient ClientM where
123123
runRequest = performRequest
124-
throwServantError = throwError
124+
throwClientError = throwError
125125

126-
runClientMOrigin :: ClientM a -> ClientEnv -> IO (Either ServantError a)
126+
runClientMOrigin :: ClientM a -> ClientEnv -> IO (Either ClientError a)
127127
runClientMOrigin cm env = runExceptT $ flip runReaderT env $ runClientM' cm
128128

129-
runClientM :: ClientM a -> IO (Either ServantError a)
129+
runClientM :: ClientM a -> IO (Either ClientError a)
130130
runClientM m = do
131131
curLoc <- getWindowLocation
132132

@@ -298,7 +298,7 @@ foreign import javascript unsafe "$3.slice($1, $1 + $2)"
298298
-- * inspecting the xhr response
299299

300300
-- This function is only supposed to handle 'ConnectionError's. Other
301-
-- 'ServantError's are created in Servant.Client.Req.
301+
-- 'ClientError's are created in Servant.Client.Req.
302302
toResponse :: JSXMLHttpRequest -> ClientM Response
303303
toResponse xhr = do
304304
status <- liftIO $ getStatus xhr

0 commit comments

Comments
 (0)