fix: improve the error logs if update bridge failed

This commit is contained in:
Shawn 2022-04-19 19:45:00 +08:00
parent 8fd6692590
commit 1b79b3f3c9
3 changed files with 11 additions and 7 deletions

View File

@ -205,7 +205,7 @@ handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) ->
key_path => ConfKeyPath,
stacktrace => ST
}),
{error, config_update_crashed}
{error, {config_update_crashed, Reason}}
end.
do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) ->

View File

@ -223,7 +223,7 @@ t_callback_crash(_Config) ->
Opts = #{rawconf_with_defaults => true},
ok = emqx_config_handler:add_handler(CrashPath, ?MODULE),
Old = emqx:get_raw_config(CrashPath),
?assertEqual({error, config_update_crashed}, emqx:update_config(CrashPath, <<"89%">>, Opts)),
?assertMatch({error, {config_update_crashed, _}}, emqx:update_config(CrashPath, <<"89%">>, Opts)),
New = emqx:get_raw_config(CrashPath),
?assertEqual(Old, New),
ok = emqx_config_handler:remove_handler(CrashPath),

View File

@ -52,7 +52,8 @@ start(Config) ->
Mountpoint = maps:get(receive_mountpoint, Config, undefined),
Subscriptions = maps:get(subscriptions, Config, undefined),
Vars = emqx_connector_mqtt_msg:make_pub_vars(Mountpoint, Subscriptions),
Handlers = make_hdlr(Parent, Vars, #{server => ip_port_to_server(Host, Port)}),
ServerStr = ip_port_to_server_str(Host, Port),
Handlers = make_hdlr(Parent, Vars, #{server => ServerStr}),
Config1 = Config#{
msg_handler => Handlers,
host => Host,
@ -70,16 +71,19 @@ start(Config) ->
catch
throw : Reason ->
ok = stop(#{client_pid => Pid}),
{error, Reason}
{error, error_reason(Reason, ServerStr)}
end;
{error, Reason} ->
ok = stop(#{client_pid => Pid}),
{error, Reason}
{error, error_reason(Reason, ServerStr)}
end;
{error, Reason} ->
{error, Reason}
{error, error_reason(Reason, ServerStr)}
end.
error_reason(Reason, ServerStr) ->
#{reason => Reason, server => ServerStr}.
stop(#{client_pid := Pid}) ->
safe_stop(Pid, fun() -> emqtt:stop(Pid) end, 1000),
ok.
@ -238,7 +242,7 @@ printable_maps(Headers) ->
(K, V0, AccIn) -> AccIn#{K => V0}
end, #{}, Headers).
ip_port_to_server(Host, Port) ->
ip_port_to_server_str(Host, Port) ->
HostStr = case inet:ntoa(Host) of
{error, einval} -> Host;
IPStr -> IPStr