Skip to content

Commit

Permalink
chore(electric): Improve error messages when the replication slot is …
Browse files Browse the repository at this point in the history
…already in use (#1226)

Related: #971.
  • Loading branch information
alco authored Jun 4, 2024
1 parent e8e4e3b commit 27ac2a1
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions components/electric/lib/electric/replication/postgres_connector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Electric.Replication.PostgresConnector do
require Logger

alias Electric.Replication.Connectors
alias Electric.Replication.Postgres.LogicalReplicationProducer
alias Electric.Replication.PostgresConnectorMng
alias Electric.Replication.PostgresConnectorSup

Expand Down Expand Up @@ -87,7 +88,7 @@ defmodule Electric.Replication.PostgresConnector do
end

defp log_child_error(
:postgres_producer,
LogicalReplicationProducer,
{:bad_return_value,
{:error,
{:error, :error, "55006", :object_in_use, "replication slot" <> _ = msg, _c_stacktrace}}},
Expand All @@ -99,12 +100,36 @@ defmodule Electric.Replication.PostgresConnector do
Failed to establish replication connection to Postgres:
#{msg}
""",
"Another instance of Electric appears to be connected to this database."
"""
Another instance of Electric appears to be connected to this database.
Refer to https://github.com/electric-sql/electric/issues/971 for additional info.
"""
)
end

defp log_child_error(
LogicalReplicationProducer,
{:bad_return_value,
{:error,
{:error, :error, "42710", :duplicate_object, "replication slot " <> _ = msg,
_c_stacktrace}}},
_connector_config
) do
Electric.Errors.print_error(
:conn,
"""
Failed to establish replication connection to Postgres:
#{msg}
""",
"""
Another instance of Electric appears to be connected to this database.
Refer to https://github.com/electric-sql/electric/issues/971 for additional info.
"""
)
end

defp log_child_error(
:postgres_producer,
LogicalReplicationProducer,
{:bad_return_value, {:error, :wal_level_not_logical}},
_connector_config
) do
Expand All @@ -119,7 +144,7 @@ defmodule Electric.Replication.PostgresConnector do
end

defp log_child_error(
:postgres_producer,
LogicalReplicationProducer,
{:bad_return_value, {:error, {:create_replication_slot_syntax_error, msg}}},
_connector_config
) do
Expand Down

0 comments on commit 27ac2a1

Please sign in to comment.