Closed cpursley closed 1 month ago
I had this a few times when starting implementation, usually happens when a handle_result doesn't have a matching case. One way I found to debug was to clone postgrex locally, use {"postgrex", path: "../postgres"} and modify the replication_connection module with the following patch
lib/postgrex/replication_connection.ex | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/lib/postgrex/replication_connection.ex b/lib/postgrex/replication_connection.ex
index 8fcde20..faccaf3 100644
--- a/lib/postgrex/replication_connection.ex
+++ b/lib/postgrex/replication_connection.ex
@@ -546,8 +546,18 @@ defmodule Postgrex.ReplicationConnection do
end
end
+ defp sapply(mod, fun, args) do
+ try do
+ apply(mod, fun, args)
+ rescue
+ error ->
+ Logger.error("REPLICATION_CONNECTION:" <> Exception.format(:error, error, __STACKTRACE__))
+ raise error
+ end
+ end
+
defp handle(mod, fun, args, from, %{streaming: streaming} = s) do
- case apply(mod, fun, args) do
+ case sapply(mod, fun, args) do
{:noreply, mod_state} ->
{:keep_state, %{s | state: {mod, mod_state}}}
with this change it give the full stacktrace and exception details for the :function_clause error
trying to reproduce locally but haven't found a way so far
otherwise doing this as the last handle_result:
@impl true
def handle_result(results, state) do
raise "Unexpected result: #{inspect(results)} for state: #{inspect(state)}"
end
should help find what case is causing the crash
Issue on master:
Originally posted by @cpursley in https://github.com/cpursley/walex/issues/57#issuecomment-2093525400
Ping @DaemonSnake