MySQL errors handling
Hello,
First of all, thanks for the library, it's really great!
I'm using sql_bridge with mysql. I noticed that the errors are only logged, and do not return for the correct treatment:
This code, from file sql_bridge_mysql_otp.erl:
query_catched(Type, DB, Q, ParamList) ->
{Q2, ParamList2} = maybe_replace_tokens(Q, ParamList),
ToRun = fun(Worker) ->
Res = mysql_query(Worker, Q2, ParamList2),
case Res of
{error, Reason} ->
error_logger:warning_msg("Error in Query.~nError: ~p~nQuery: ~s",[Reason, Q]);
_ ->
ok
end,
case Type of
insert -> mysql:insert_id(Worker);
update -> mysql:affected_rows(Worker);
_ -> Res
end
end,
case sql_bridge_utils:with_poolboy_pool(DB, ToRun) of
{error, Reason} -> {error, Reason};
Result ->
{ok, format_result(Type, Result)}
end.
The error is just reported with a log, when ideally it would be returned to the caller. Does this have any special reason?
Hi @mobilemindtec I can't believe I never responded to this.
The reason it handles it this way is a side effect of some older projects I have where an error of this nature is simply ignored or passed over, and in my laziness, I didn't want to rework those projects or find exactly where those errors are.
I might be inclined to add an option on how to handle these kinds of errors.
Thanks again for the feedback and that's a good question.