diff --git a/components/electric/lib/electric/postgres/connection_pool.ex b/components/electric/lib/electric/postgres/connection_pool.ex index b6ce136f50..b6518b4ce9 100644 --- a/components/electric/lib/electric/postgres/connection_pool.ex +++ b/components/electric/lib/electric/postgres/connection_pool.ex @@ -32,13 +32,21 @@ defmodule Electric.Postgres.ConnectionPool do NimblePool.checkout!( pool, :checkout, - fn _pool, conn -> - {fun.(conn), :ok} - end, + fn _pool, conn -> {execute_fun_with_conn(fun, conn), :ok} end, @pool_timeout ) end + defp execute_fun_with_conn(fun, conn) do + try do + fun.(conn) + rescue + e -> + Logger.error(Exception.format(:error, e, __STACKTRACE__)) + {:error, e} + end + end + @spec name(Connectors.origin()) :: Electric.reg_name() def name(origin) when is_binary(origin) do Electric.name(__MODULE__, origin)