Skip to content

Commit

Permalink
chore: improve error context
Browse files Browse the repository at this point in the history
instead of crashing lists:zip with a function_clause
  • Loading branch information
zmstone committed Sep 27, 2024
1 parent 343d96a commit c4e4940
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/commands/epgsql_cmd_prepared_query2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ execute(Sock, #pquery2{name = Name, params = Params} = State) ->
},
{finish, {error, Error}, Sock};
#statement{types = Types} = Stmt ->
TypedParams = lists:zip(Types, Params),
TypedParams = zip(Name, Types, Params),
#statement{name = StatementName, columns = Columns} = Stmt,
Codec = epgsql_sock:get_codec(Sock),
Bin1 = epgsql_wire:encode_parameters(TypedParams, Codec),
Expand All @@ -58,6 +58,19 @@ execute(Sock, #pquery2{name = Name, params = Params} = State) ->
{send_multi, Commands, Sock, State#pquery2{stmt = Stmt}}
end.

zip(Name, Types, Params) ->
case length(Types) =:= length(Params) of
true ->
lists:zip(Types, Params);
false ->
error(#{cause => "prepared_data_types_and_column_count_mismatch",
name => Name,
types => Types,
types_count => length(Types),
values_count => length(Params)
})
end.

%% prepared query
handle_message(?BIND_COMPLETE, <<>>, Sock, #pquery2{stmt = Stmt} = State) ->
#statement{columns = Columns} = Stmt,
Expand Down

0 comments on commit c4e4940

Please sign in to comment.