Comments (4)
Right, when type families conflict that much their answers have to "be compatible".
I'm thinking it might be worth putting all our brainpower on haskell-servant/servant#841 instead of fighting that kind of problem =) If we re-engineer Verb
to allow us to specify an (optional) list of "sad paths" in addition to the happy path that it knows about at the moment, we might get the best of both worlds and get rid once and for all of all those overlapping instances, if we play our moves right.
from servant-checked-exceptions.
I think this should be mostly fixed with #6.
I think the only thing left is to handle apis that set Headers.
from servant-checked-exceptions.
Today I tried to add support for handling APIs that set Headers, but I have run into some difficulty.
Here is the existing instance for Throwing
:
-- | When @'Throwing' es@ comes before a 'Verb', change it into the same 'Verb'
-- but returning an @'Envelope' es@.
instance
{-# OVERLAPPABLE #-}
(HasServer (Verb method status ctypes (Envelope es a)) context) =>
HasServer (Throwing es :> Verb method status ctypes a) context where
type ServerT (Throwing es :> Verb method status ctypes a) m =
ServerT (Verb method status ctypes (Envelope es a)) m
route
:: Proxy (Throwing es :> Verb method status ctypes a)
-> Context context
-> Delayed env (ServerT (Verb method status ctypes (Envelope es a)) Handler)
-> Router env
route _ = route (Proxy :: Proxy (Verb method status ctypes (Envelope es a)))
I tried to add an additional instance for use with Headers
that looks like this:
instance
{-# OVERLAPPING #-}
(HasServer (Verb method status ctypes (Headers h (Envelope es a))) context) =>
HasServer (Throwing es :> Verb method status ctypes (Headers h a)) context where
type ServerT (Throwing es :> Verb method status ctypes (Headers h a)) m =
ServerT (Verb method status ctypes (Headers h (Envelope es a))) m
route
:: Proxy (Throwing es :> Verb method status ctypes (Headers h a))
-> Context context
-> Delayed
env
( ServerT
(Verb method status ctypes (Headers h (Envelope es a)))
Handler
)
-> Router env
route _ =
route (Proxy :: Proxy (Verb method status ctypes (Headers h (Envelope es a))))
However, this is failing with the following error:
src/Servant/Checked/Exceptions/Internal/Servant/Server.hs:61:8: error:
Conflicting family instance declarations:
forall k1 a (ctypes :: [*]) (status :: Nat) (method :: k1) (es :: [*]) (m :: * -> *).
ServerT (Throwing es :> Verb method status ctypes a) m =
ServerT (Verb method status ctypes (Envelope es a)) m
-- Defined at src/Servant/Checked/Exceptions/Internal/Servant/Server.hs:61:8
forall k1 a (h :: [*]) (ctypes :: [*]) (status :: Nat) (method :: k1) (es :: [*]) (m :: * -> *).
ServerT (Throwing es :> Verb method status ctypes (Headers h a)) m =
ServerT (Verb method status ctypes (Headers h (Envelope es a))) m
-- Defined at src/Servant/Checked/Exceptions/Internal/Servant/Server.hs:80:8
Here are some links related to this error:
- https://stackoverflow.com/questions/24979145/how-to-solve-conflicting-instance-in-type-families
- https://ghc.haskell.org/trac/ghc/ticket/4259
- https://ghc.haskell.org/trac/ghc/ticket/4246
- https://ghc.haskell.org/trac/ghc/ticket/13931
It doesn't look like there is an easy way to fix this.
from servant-checked-exceptions.
It looks like servant-auth defines a single type class and related type family for determining how to modify the response type to add headers:
I wonder if something similar to this could be adopted for servant-checked-exceptions.
from servant-checked-exceptions.
Related Issues (20)
- add note about having to be careful with letting aeson derive FromJSON and ToJSON instances
- Build failure with latest servant libraries HOT 1
- break out union and open-union into separate library HOT 1
- update Servant.Checked.Exceptions.Internal.Servant.Docs to show http error status codes
- break the main Servant.Checked.Exceptions module up into a couple different modules
- add documentation for `ErrStatus` class HOT 1
- possibly write servant cookbook entry for servant-checked-exceptions
- Break into combinator/backend packages HOT 4
- servant-client doesn't return envelopes for non-2xx status codes HOT 4
- How can we perform case analysis on envelopes? HOT 2
- Build failure with servant 0.16 HOT 4
- support servant-0.16 HOT 2
- rewrite servant-checked-exceptions in terms of uverb
- fix doctests on GHC-9 HOT 1
- NamedRoutes not implemented HOT 4
- Simplify the From/ToJSON instances for Envelope HOT 11
- Ability to place Throws/Throwing before multiple grouped route definitions
- add some tests to make sure that the HasServer and HasClient instances are correct HOT 1
- add to stackage HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from servant-checked-exceptions.