Skip to content

Incomprehensible error message (with solution in piece of documentation that's been removed) #1839

@kephas

Description

@kephas

I forgot to derive Generic for my API records and it got me the following error message:

 src/DrivingAdapters/WebServer.hs:23:33: error: [GHC-18872]
    • Couldn't match type: ServerT
                             (Servant.API.Generic.GToServant
                                (GHC.Generics.Rep (MyAPI AsApi)))
                             (Sem r)
                     with: Servant.API.Generic.GToServant
                             (GHC.Generics.Rep
                                (MyAPI (Servant.Server.Internal.AsServerT (Sem r))))
        arising from a use of ‘genericServeT’
    • In the second argument of ‘($)’, namely
        ‘genericServeT lower server’

And this didn't help me find the issue. When I searched online, I stumbled upon the cookbook in version 0.16, that mentions this:

It’s recommented to use genericApi function, as then you’ll get better error message, for example if you forget to derive Generic.

Indeed, if I add this:

_witness :: Proxy (ToServantApi MyAPI)
_witness = genericApi (Proxy :: Proxy MyAPI)

I also get the following:

src/DrivingAdapters/WebServer.hs:26:12: error: [GHC-39999]
    • No instance for ‘Generic (MyAPI AsApi)’
        arising from a use of ‘genericApi’
    • In the expression: genericApi (Proxy :: Proxy MyAPI)
      In an equation for ‘_witness’:
          _witness = genericApi (Proxy :: Proxy MyAPI)

That latter error message would appear about genericServeT if there wasn't the constraint ServerT (ToServantApi routes) m ~ ToServant routes (AsServerT m).

If it's not possible to change the error on genericServeT, it would be nice to add a warning in the documentation and/or the trick with genericApi.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions