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, key_path => ConfKeyPath,
stacktrace => ST stacktrace => ST
}), }),
{error, config_update_crashed} {error, {config_update_crashed, Reason}}
end. end.
do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) -> do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) ->

View File

@ -223,7 +223,7 @@ t_callback_crash(_Config) ->
Opts = #{rawconf_with_defaults => true}, Opts = #{rawconf_with_defaults => true},
ok = emqx_config_handler:add_handler(CrashPath, ?MODULE), ok = emqx_config_handler:add_handler(CrashPath, ?MODULE),
Old = emqx:get_raw_config(CrashPath), 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), New = emqx:get_raw_config(CrashPath),
?assertEqual(Old, New), ?assertEqual(Old, New),
ok = emqx_config_handler:remove_handler(CrashPath), ok = emqx_config_handler:remove_handler(CrashPath),

View File

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