elixir-ecto / db_connection

Database connection behaviour
http://hexdocs.pm/db_connection/DBConnection.html
309 stars 112 forks source link

Turn `ConnectionError` into an error tuple (vs exception) #260

Closed acco closed 2 years ago

acco commented 2 years ago

Hey team,

DbConnection.ConnectionErrors happen. We obviously have worked to minimize, but there are some high-volume tables in our app that will run into this issue from time to time.

The problem is that unlike other errors, a ConnectionError is an exception. This complicates our control flow: instead of being able to use a with clause to handle all the possible things that can go wrong, we have to do some extra try/rescue wrapping to handle these exceptions.

Is there any appetite for making this behavior configurable? Or am I missing something here? It would be great to have a start_link/1 setting that flipped connection errors to a tuple instead of an exception. With some guidance, I'd be happy to help make it happen.

josevalim commented 2 years ago

I would love to see a PR exploring this and we can decide based on that if it is not too much work.

acco commented 2 years ago

Ok @josevalim ! I'll see what I can whip up

jbavari commented 2 years ago

@josevalim Would love any feedback you have on a PR I put together. Thank you in advance.

acco commented 2 years ago

Per https://github.com/elixir-ecto/db_connection/pull/264#issuecomment-1161358040, think it makes the most sense to just funnel all calls to Postgrex.query into one location in our app and rescue the exception. Thanks all!