Skip to content

Commit

Permalink
fix uncaught exception on bad raw text value being encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter committed Nov 21, 2024
1 parent 1033dbd commit 16782cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pg_raw.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ init(_Opts) ->
<<"byteasend">>, <<"unknownsend">>,
<<"citextsend">>], []}.

encode(Text, _) ->
encode(Text, _) when is_list(Text) ->
[<<(iolist_size(Text)):?int32>>, Text].

decode(Text, _) ->
Expand Down
16 changes: 11 additions & 5 deletions src/pg_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ encode(Value, TypeInfo=#type_info{module=Module}) ->
try
Module:encode(Value, TypeInfo)
catch
error:function_clause ->
erlang:error(#{error => badarg_encoding,
module => ?MODULE,
value => Value,
type_info => TypeInfo})
error:function_clause:Stacktrace ->
erlang:raise(error, #{error => badarg_encoding,
module => ?MODULE,
value => Value,
type_info => TypeInfo}, Stacktrace);
error:badarg:Stacktrace ->
erlang:raise(error, #{error => badarg_encoding,
module => ?MODULE,
value => Value,
type_info => TypeInfo}, Stacktrace)

end.

-spec decode(binary(), type_info()) -> term().
Expand Down

0 comments on commit 16782cc

Please sign in to comment.