Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stop instead of raise on genstatem #320

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/db_connection/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ defmodule DBConnection.Connection do
rescue
e ->
{e, stack} = maybe_sanitize_exception(e, __STACKTRACE__, opts)
reraise e, stack
# Because of versions of Elixir before 1.17.2 not handling genstatem error logs correctly,
# we need to send a stop event here instead of raising.
{:stop, {e, stack}}
else
{:ok, state} when after_connect != nil ->
ref = make_ref()
Expand Down Expand Up @@ -340,8 +342,13 @@ defmodule DBConnection.Connection do

@doc false
@impl :gen_statem
# If client is :closed then the connection was previously disconnected
# and cleanup is not required.
# Once Elixir 1.17 is required, we can change this to do nothing, and raise on error instead of sending :stop.
def terminate({e, stack}, _, %{client: :closed}) do
msg = Exception.format_banner(:error, e, stack)
Logger.error(msg)
:ok
end

def terminate(_, _, %{client: :closed}), do: :ok

def terminate(reason, _, s) do
Expand Down