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.
I forgot to derive
Genericfor my API records and it got me the following error message: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:
Indeed, if I add this:
I also get the following:
That latter error message would appear about
genericServeTif there wasn't the constraintServerT (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 withgenericApi.