Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/light-pandas-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@core/sync-service': patch
---

Ignore failures to rollback a transaction when handling a shape db write exception.
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ defmodule Electric.ShapeCache.ShapeStatus.ShapeDb.Connection do
result
rescue
e ->
:ok = execute(conn, "ROLLBACK")
_ = execute(conn, "ROLLBACK")
reraise e, __STACKTRACE__
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,4 +609,17 @@ defmodule Electric.ShapeCache.ShapeStatus.ShapeDbTest do
)
end
end

describe "error handling" do
test "errors raised within transaction do not cause errors attempting to rollback", ctx do
assert_raise RuntimeError, "source error", fn ->
ShapeDb.Connection.checkout_write!(ctx.stack_id, :raising, fn %{conn: conn} ->
# commit the txn so that attempting to rollback after the exception
# will return an error
:ok = ShapeDb.Connection.execute(conn, "COMMIT")
raise RuntimeError, "source error"
end)
end
end
end
end