Does Repo.all always succeeds?


I have an application in Elixir that is using Ecto. According to the documentation, if my query is well formed, Repo.all will always succeed by returning a [Ecto.Schema.t()].


However, I am not sure about this claim.

  • What happens if my database is overloaded and times out?
  • Or if the connection drops?

I don’t think Repo.all will wait indefinitely. Will this function return with an error, or raise an exception?

What are the best practices to deal with such scenarios?

It will raise an exception.

How do you generally deal with this?
Do you just let everything crash and burn, or do you try to use try/catch and recover from there?
Are there any community guidelines?

This is a case by case decision, you’ll have to make.

There are a few questions, which might help though:

  • Is there a user involved, which needs a more useful error message than 500/crash?
  • Is this an exceptional case (people are alerted if db is down) or is it not (the db outside of your control and could be down anytime)?
  • Is there something useful you can and want to do in case of an exception?
  • Is there any other layers, which might already rescue exceptions (e.g. phoenix)?