fix: let crash when plugin not found in cluster
This commit is contained in:
parent
19e039e0d2
commit
28293284a7
|
@ -597,6 +597,9 @@ delete_package(Name) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% for RPC plugin update
|
%% for RPC plugin update
|
||||||
|
%% TODO: catch thrown error to return 400
|
||||||
|
%% - plugin_not_found
|
||||||
|
%% - otp vsn assertion failed
|
||||||
ensure_action(Name, start) ->
|
ensure_action(Name, start) ->
|
||||||
_ = emqx_plugins:ensure_started(Name),
|
_ = emqx_plugins:ensure_started(Name),
|
||||||
_ = emqx_plugins:ensure_enabled(Name),
|
_ = emqx_plugins:ensure_enabled(Name),
|
||||||
|
|
|
@ -279,9 +279,9 @@ ensure_started(NameVsn) ->
|
||||||
case do_ensure_started(NameVsn) of
|
case do_ensure_started(NameVsn) of
|
||||||
ok ->
|
ok ->
|
||||||
ok;
|
ok;
|
||||||
{error, Reason} ->
|
{error, ReasonMap} ->
|
||||||
?SLOG(alert, Reason#{msg => "failed_to_start_plugin"}),
|
?SLOG(alert, ReasonMap#{msg => "failed_to_start_plugin"}),
|
||||||
{error, Reason}
|
{error, ReasonMap}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @doc Stop all plugins before broker stops.
|
%% @doc Stop all plugins before broker stops.
|
||||||
|
@ -664,12 +664,12 @@ do_ensure_started(NameVsn) ->
|
||||||
ok ->
|
ok ->
|
||||||
Plugin = do_read_plugin(NameVsn),
|
Plugin = do_read_plugin(NameVsn),
|
||||||
ok = load_code_start_apps(NameVsn, Plugin);
|
ok = load_code_start_apps(NameVsn, Plugin);
|
||||||
{error, plugin_not_found} ->
|
{error, #{reason := Reason} = ReasonMap} ->
|
||||||
?SLOG(error, #{
|
?SLOG(error, #{
|
||||||
error_msg => "plugin_not_found",
|
error_msg => string_reason(Reason),
|
||||||
name_vsn => NameVsn
|
name_vsn => NameVsn
|
||||||
}),
|
}),
|
||||||
ok
|
{error, ReasonMap}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
).
|
).
|
||||||
|
@ -772,7 +772,7 @@ do_get_from_cluster(NameVsn) ->
|
||||||
error_msg => "failed_to_copy_plugin_from_other_nodes",
|
error_msg => "failed_to_copy_plugin_from_other_nodes",
|
||||||
name_vsn => NameVsn,
|
name_vsn => NameVsn,
|
||||||
node_errors => NodeErrors,
|
node_errors => NodeErrors,
|
||||||
reason => not_found
|
reason => plugin_not_found
|
||||||
},
|
},
|
||||||
?SLOG(error, ErrMeta),
|
?SLOG(error, ErrMeta),
|
||||||
{error, ErrMeta};
|
{error, ErrMeta};
|
||||||
|
@ -780,7 +780,7 @@ do_get_from_cluster(NameVsn) ->
|
||||||
ErrMeta = #{
|
ErrMeta = #{
|
||||||
error_msg => "no_nodes_to_copy_plugin_from",
|
error_msg => "no_nodes_to_copy_plugin_from",
|
||||||
name_vsn => NameVsn,
|
name_vsn => NameVsn,
|
||||||
reason => not_found
|
reason => plugin_not_found
|
||||||
},
|
},
|
||||||
?SLOG(error, ErrMeta),
|
?SLOG(error, ErrMeta),
|
||||||
{error, ErrMeta}
|
{error, ErrMeta}
|
||||||
|
@ -1497,3 +1497,8 @@ bin(B) when is_binary(B) -> B.
|
||||||
|
|
||||||
wrap_to_list(Path) ->
|
wrap_to_list(Path) ->
|
||||||
binary_to_list(iolist_to_binary(Path)).
|
binary_to_list(iolist_to_binary(Path)).
|
||||||
|
|
||||||
|
string_reason(plugin_not_found) ->
|
||||||
|
"plugin_not_found";
|
||||||
|
string_reason(_) ->
|
||||||
|
"unexpected_error".
|
||||||
|
|
|
@ -390,7 +390,7 @@ t_bad_tar_gz(Config) ->
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{error, #{
|
{error, #{
|
||||||
error_msg := "no_nodes_to_copy_plugin_from",
|
error_msg := "no_nodes_to_copy_plugin_from",
|
||||||
reason := not_found
|
reason := plugin_not_found
|
||||||
}},
|
}},
|
||||||
emqx_plugins:ensure_installed("nonexisting")
|
emqx_plugins:ensure_installed("nonexisting")
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue