haskell-servant / haskell-servant/servant

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

Open
#1,839 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
2k
Forks
427
Avg merge
2d 23h
Merged PRs (30d)
5

Description

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:

```haskell
_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`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.