Skip to content

Commit 2f5b7d4

Browse files
authored
fix: ensure smooth upgrade for filesystem KV format change (#2384)
1 parent 7ea8833 commit 2f5b7d4

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

.changeset/plenty-spies-pretend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@core/sync-service": patch
3+
---
4+
5+
fix: ensure smooth upgrade for filesystem KV format change

packages/sync-service/lib/electric/persistent_kv/filesystem.ex

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@ defmodule Electric.PersistentKV.Filesystem do
1515
path = join(fs, key)
1616

1717
case File.read(path) do
18-
{:ok, data} -> {:ok, :erlang.binary_to_term(data)}
19-
{:error, :enoent} -> {:error, :not_found}
20-
error -> error
18+
{:ok, data} ->
19+
try do
20+
{:ok, :erlang.binary_to_term(data)}
21+
rescue
22+
ArgumentError ->
23+
# This was before we added `term_to_binary` to the filesystem.
24+
# We can treat data as a plain string
25+
{:ok, data}
26+
end
27+
28+
{:error, :enoent} ->
29+
{:error, :not_found}
30+
31+
error ->
32+
error
2133
end
2234
end
2335

0 commit comments

Comments
 (0)