nikita-volkov / hasql-pool

A pool of connections for Hasql
http://hackage.haskell.org/package/hasql-pool
MIT License
17 stars 15 forks source link

Add Exception instance for UsageError #2

Closed domenkozar closed 5 years ago

domenkozar commented 5 years ago

Makes escalation via MonadThrow easier.

nikita-volkov commented 5 years ago

I must say that I'm a bit conflicted about that. On the one hand it's just a simple instance, which doesn't break any APIs, on the other it goes against my intention of establishing an exceptionless workflow. Can you provide more details on your motivation and maybe some arguments?

domenkozar commented 5 years ago

@nikita-volkov I use exceptions within HTTP request handling to trigger HTTP 500 response if SQL connection fails. I really enjoy hasql being exceptionless, but servant only uses exceptions to trigger non-200 responses.

nikita-volkov commented 5 years ago

Seems like it's the issue of Servant. Have you tried reporting it there?

domenkozar commented 5 years ago

It's by design to use exception in Servant. I don't see how this would hurt hasql by providing an instance so that code outside the library can use it instead of relying on orphans.

nikita-volkov commented 5 years ago

Well, it's also by design not to use exceptions in Hasql and Hasql's error messages are not exceptions, so it doesn't make sense to make them the instances of. Also I don't believe that it would be correct of me to rely the design decisions on the arguments about convenience of interaction with any third-party library, because thus I would introduce a dependency of Hasql's design on the design of the other library.

Concerning Servant, it doesn't seem like a stopper issue in terms of integration with it, since you can use custom wrapper types, which are exceptions, to pack Hasql errors when you actually do throw exceptions.