Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL errors handling #9

Open
mobilemindtec opened this issue Nov 23, 2022 · 1 comment
Open

MySQL errors handling #9

mobilemindtec opened this issue Nov 23, 2022 · 1 comment

Comments

@mobilemindtec
Copy link

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?

@choptastic
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants