fix(mysql_bridge): check prepare statement error messages
Fixes https://emqx.atlassian.net/browse/EMQX-11648
This commit is contained in:
parent
cc00dd80ee
commit
d0588b86b5
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_bridge_mysql, [
|
{application, emqx_bridge_mysql, [
|
||||||
{description, "EMQX Enterprise MySQL Bridge"},
|
{description, "EMQX Enterprise MySQL Bridge"},
|
||||||
{vsn, "0.1.3"},
|
{vsn, "0.1.4"},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications, [
|
{applications, [
|
||||||
kernel,
|
kernel,
|
||||||
|
|
|
@ -39,11 +39,23 @@ on_add_channel(
|
||||||
ok ->
|
ok ->
|
||||||
ChannelConfig2 = maps:merge(ChannelConfig1, QueryTemplates),
|
ChannelConfig2 = maps:merge(ChannelConfig1, QueryTemplates),
|
||||||
ChannelConfig = set_prepares(ChannelConfig2, ConnectorState),
|
ChannelConfig = set_prepares(ChannelConfig2, ConnectorState),
|
||||||
|
case maps:get(prepares, ChannelConfig) of
|
||||||
|
{error, {Code, ErrState, Msg}} ->
|
||||||
|
Context = #{
|
||||||
|
code => Code,
|
||||||
|
state => ErrState,
|
||||||
|
message => Msg
|
||||||
|
},
|
||||||
|
{error, {prepare_statement, Context}};
|
||||||
|
{error, undefined_table} ->
|
||||||
|
{error, {unhealthy_target, <<"Undefined table">>}};
|
||||||
|
_ ->
|
||||||
State = State0#{
|
State = State0#{
|
||||||
channels => maps:put(ChannelId, ChannelConfig, Channels),
|
channels => maps:put(ChannelId, ChannelConfig, Channels),
|
||||||
connector_state => ConnectorState
|
connector_state => ConnectorState
|
||||||
},
|
},
|
||||||
{ok, State};
|
{ok, State}
|
||||||
|
end;
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
{error, Error}
|
{error, Error}
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -50,7 +50,8 @@ groups() ->
|
||||||
NonBatchCases = [
|
NonBatchCases = [
|
||||||
t_write_timeout,
|
t_write_timeout,
|
||||||
t_uninitialized_prepared_statement,
|
t_uninitialized_prepared_statement,
|
||||||
t_non_batch_update_is_allowed
|
t_non_batch_update_is_allowed,
|
||||||
|
t_undefined_field_in_sql
|
||||||
],
|
],
|
||||||
OnlyBatchCases = [
|
OnlyBatchCases = [
|
||||||
t_batch_update_is_forbidden
|
t_batch_update_is_forbidden
|
||||||
|
@ -801,27 +802,13 @@ t_missing_table(Config) ->
|
||||||
sync ->
|
sync ->
|
||||||
query_resource(Config, Request);
|
query_resource(Config, Request);
|
||||||
async ->
|
async ->
|
||||||
{_, Ref} = query_resource_async(Config, Request),
|
{Res, _Ref} = query_resource_async(Config, Request),
|
||||||
{ok, Res} = receive_result(Ref, 2_000),
|
|
||||||
Res
|
Res
|
||||||
end,
|
end,
|
||||||
|
|
||||||
BatchSize = ?config(batch_size, Config),
|
|
||||||
IsBatch = BatchSize > 1,
|
|
||||||
case IsBatch of
|
|
||||||
true ->
|
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{error,
|
{error, {resource_error, #{reason := unhealthy_target}}},
|
||||||
{unrecoverable_error,
|
|
||||||
{1146, <<"42S02">>, <<"Table 'mqtt.mqtt_test' doesn't exist">>}}},
|
|
||||||
Result
|
Result
|
||||||
);
|
),
|
||||||
false ->
|
|
||||||
?assertMatch(
|
|
||||||
{error, undefined_table},
|
|
||||||
Result
|
|
||||||
)
|
|
||||||
end,
|
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
fun(Trace) ->
|
fun(Trace) ->
|
||||||
|
@ -974,3 +961,31 @@ t_non_batch_update_is_allowed(Config) ->
|
||||||
[]
|
[]
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
t_undefined_field_in_sql(Config) ->
|
||||||
|
?check_trace(
|
||||||
|
begin
|
||||||
|
Overrides = #{
|
||||||
|
<<"sql">> =>
|
||||||
|
<<
|
||||||
|
"INSERT INTO mqtt_test(wrong_column, arrived) "
|
||||||
|
"VALUES (${payload}, FROM_UNIXTIME(${timestamp}/1000))"
|
||||||
|
>>
|
||||||
|
},
|
||||||
|
ProbeRes = emqx_bridge_testlib:probe_bridge_api(Config, Overrides),
|
||||||
|
?assertMatch({error, {{_, 400, _}, _, _BodyRaw}}, ProbeRes),
|
||||||
|
{error, {{_, 400, _}, _, BodyRaw}} = ProbeRes,
|
||||||
|
?assertEqual(
|
||||||
|
match,
|
||||||
|
re:run(
|
||||||
|
BodyRaw,
|
||||||
|
<<"Unknown column 'wrong_column' in 'field list'">>,
|
||||||
|
[{capture, none}]
|
||||||
|
),
|
||||||
|
#{body => BodyRaw}
|
||||||
|
),
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
[]
|
||||||
|
),
|
||||||
|
ok.
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Improved HTTP API error message when the creation of a MySQL bridge fails.
|
Loading…
Reference in New Issue