@@ -56,7 +56,7 @@ import qualified Data.Text as T
56import Data.Typeable
56import Data.Typeable
57import GHC.Generics
57import GHC.Generics
58import GHC.TypeLits
58import GHC.TypeLits
59− (KnownNat, KnownSymbol, symbolVal)
59+ (KnownNat, KnownSymbol, TypeError, symbolVal)
60import qualified Network.HTTP.Media as NHM
60import qualified Network.HTTP.Media as NHM
61import Network.HTTP.Types hiding
61import Network.HTTP.Types hiding
62 (Header, ResponseHeaders)
62 (Header, ResponseHeaders)
@@ -90,6 +90,7 @@ import Servant.API.ResponseHeaders
90import Servant.API.Status
90import Servant.API.Status
91 (statusFromNat)
91 (statusFromNat)
92import qualified Servant.Types.SourceT as S
92import qualified Servant.Types.SourceT as S
93+import Servant.API.TypeErrors
93import Web.HttpApiData
94import Web.HttpApiData
94 (FromHttpApiData, parseHeader, parseQueryParam, parseUrlPiece,
95 (FromHttpApiData, parseHeader, parseQueryParam, parseUrlPiece,
95 parseUrlPieces)
96 parseUrlPieces)
@@ -814,38 +815,15 @@ instance (HasContextEntry context (NamedContext name subContext), HasServer subA
814 hoistServerWithContext _ _ nt s = hoistServerWithContext (Proxy :: Proxy subApi) (Proxy :: Proxy subContext) nt s
815 hoistServerWithContext _ _ nt s = hoistServerWithContext (Proxy :: Proxy subApi) (Proxy :: Proxy subContext) nt s
816-------------------------------------------------------------------------------
817-------------------------------------------------------------------------------
817−-- TypeError helpers
818+-- Custom type errors
818-------------------------------------------------------------------------------
819-------------------------------------------------------------------------------
820−-- | This instance catches mistakes when there are non-saturated
821+-- Erroring instance for 'HasServer' when a combinator is not fully applied
821−-- type applications on LHS of ':>'.
823−-- >>> serve (Proxy :: Proxy (Capture "foo" :> Get '[JSON] Int)) (error "...")
825−-- ...Expected something of kind Symbol or *, got: k -> l on the LHS of ':>'.
826−-- ...Maybe you haven't applied enough arguments to
827−-- ...Capture' '[] "foo"
830−-- >>> undefined :: Server (Capture "foo" :> Get '[JSON] Int)
832−-- ...Expected something of kind Symbol or *, got: k -> l on the LHS of ':>'.
833−-- ...Maybe you haven't applied enough arguments to
834−-- ...Capture' '[] "foo"
837−instance TypeError (HasServerArrowKindError arr) => HasServer ((arr :: k -> l) :> api) context
822+instance TypeError (PartialApplication HasServer arr) => HasServer ((arr :: a -> b) :> sub) context
839− type ServerT (arr :> api) m = TypeError (HasServerArrowKindError arr)
824+ type ServerT (arr :> sub) _ = TypeError (PartialApplication HasServer arr)
840− -- it doesn't really matter what sub route we peak
825+ route = error "unreachable"
841− route _ _ _ = error "servant-server panic: impossible happened in HasServer (arr :> api)"
842− hoistServerWithContext _ _ _ = id
826+ hoistServerWithContext _ _ _ _ = error "unreachable"
844−-- Cannot have TypeError here, otherwise use of this symbol will error :)
845−type HasServerArrowKindError arr =
846− 'Text "Expected something of kind Symbol or *, got: k -> l on the LHS of ':>'."
847− ':$$: 'Text "Maybe you haven't applied enough arguments to"
850-- | This instance prevents from accidentally using '->' instead of ':>'
828-- | This instance prevents from accidentally using '->' instead of ':>'
@@ -880,6 +858,15 @@ type HasServerArrowTypeError a b =
880 ':$$: 'Text "and"
858 ':$$: 'Text "and"
881 ':$$: 'ShowType b
859 ':$$: 'ShowType b
861+-- Erroring instances for 'HasServer' for unknown API combinators
863+-- XXX: This omits the @context@ parameter, e.g.:
865+-- "There is no instance for HasServer (Bool :> …)". Do we care ?
866+instance {-# OVERLAPPABLE #-} TypeError (NoInstanceForSub HasServer ty) => HasServer (ty :> sub) context
868+instance {-# OVERLAPPABLE #-} TypeError (NoInstanceFor (HasServer api context)) => HasServer api context
883-- | Ignore @'Fragment'@ in server handlers.
870-- | Ignore @'Fragment'@ in server handlers.
884-- See <https://ietf.org/rfc/rfc2616.html#section-15.1.3> for more details.
871-- See <https://ietf.org/rfc/rfc2616.html#section-15.1.3> for more details.