Skip to content

How to make "createPool" fail fast when given a bad connection string? #33

@runeksvendsen

Description

@runeksvendsen

Hi there,

Thanks for creating this library!

I have a question about how to make the following servant example using resource-pool fail immediately when given an invalid connection string: https://haskell-servant.readthedocs.io/en/stable/cookbook/db-postgres-pool/PostgresPool.html

If the main function of the example is modified to only start the server:

main :: IO ()
main = do
  -- you could read this from some configuration file,
  -- environment variable or somewhere else instead.
  -- you will need to either change this connection string OR
  -- set some environment variables (see
  -- https://www.postgresql.org/docs/9.5/static/libpq-envars.html)
  -- to point to a running PostgreSQL server for this example to work.
  let connStr = ""
  pool <- initConnectionPool connStr
  runApp pool

the server will happily start without errors, but throw an exception each time a request is handled (because connStr is invalid).

Shouldn't createPool create a resource pool immediately -- and thus fail at this point -- rather than wait until withResource is called?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions