Skip to content

Commit

Permalink
add logging for failures to parse values
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetised committed Oct 31, 2024
1 parent f5f99d7 commit f4847c0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/elixir-client/lib/electric/client/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,40 @@ defmodule Electric.Client.Message do
offset: Offset.t()
}

require Logger

def from_message(msg, value_mapping_fun) do
%{
"headers" => headers,
"offset" => offset,
"value" => value
"value" => raw_value
} = msg

value =
try do
value_mapping_fun.(raw_value)
rescue
exception ->
Logger.error(
"Unable to cast field values: #{Exception.format(:error, exception, __STACKTRACE__)}"
)

reraise exception, __STACKTRACE__
end

%__MODULE__{
key: msg["key"],
offset: Client.Offset.from_string!(offset),
headers: Headers.from_message(headers),
value: value_mapping_fun.(value)
value: value
}
end
end

defmodule ResumeMessage do
@moduledoc """
Emitted by the synchronisation stream before terminating early. If passed
as an option to [`Client.stream`](`Electric.Client.stream/3`) allows for
as an option to [`Client.stream/3`](`Electric.Client.stream/3`) allows for
resuming a shape stream at the given point.
E.g.
Expand Down

0 comments on commit f4847c0

Please sign in to comment.