fix: let crash when plugin not found in cluster

This commit is contained in:
JimMoen 2024-06-18 16:41:06 +08:00
parent 19e039e0d2
commit 28293284a7
No known key found for this signature in database
3 changed files with 17 additions and 9 deletions

View File

@ -597,6 +597,9 @@ delete_package(Name) ->
end.
%% for RPC plugin update
%% TODO: catch thrown error to return 400
%% - plugin_not_found
%% - otp vsn assertion failed
ensure_action(Name, start) ->
_ = emqx_plugins:ensure_started(Name),
_ = emqx_plugins:ensure_enabled(Name),

View File

@ -279,9 +279,9 @@ ensure_started(NameVsn) ->
case do_ensure_started(NameVsn) of
ok ->
ok;
{error, Reason} ->
?SLOG(alert, Reason#{msg => "failed_to_start_plugin"}),
{error, Reason}
{error, ReasonMap} ->
?SLOG(alert, ReasonMap#{msg => "failed_to_start_plugin"}),
{error, ReasonMap}
end.
%% @doc Stop all plugins before broker stops.
@ -664,12 +664,12 @@ do_ensure_started(NameVsn) ->
ok ->
Plugin = do_read_plugin(NameVsn),
ok = load_code_start_apps(NameVsn, Plugin);
{error, plugin_not_found} ->
{error, #{reason := Reason} = ReasonMap} ->
?SLOG(error, #{
error_msg => "plugin_not_found",
error_msg => string_reason(Reason),
name_vsn => NameVsn
}),
ok
{error, ReasonMap}
end
end
).
@ -772,7 +772,7 @@ do_get_from_cluster(NameVsn) ->
error_msg => "failed_to_copy_plugin_from_other_nodes",
name_vsn => NameVsn,
node_errors => NodeErrors,
reason => not_found
reason => plugin_not_found
},
?SLOG(error, ErrMeta),
{error, ErrMeta};
@ -780,7 +780,7 @@ do_get_from_cluster(NameVsn) ->
ErrMeta = #{
error_msg => "no_nodes_to_copy_plugin_from",
name_vsn => NameVsn,
reason => not_found
reason => plugin_not_found
},
?SLOG(error, ErrMeta),
{error, ErrMeta}
@ -1497,3 +1497,8 @@ bin(B) when is_binary(B) -> B.
wrap_to_list(Path) ->
binary_to_list(iolist_to_binary(Path)).
string_reason(plugin_not_found) ->
"plugin_not_found";
string_reason(_) ->
"unexpected_error".

View File

@ -390,7 +390,7 @@ t_bad_tar_gz(Config) ->
?assertMatch(
{error, #{
error_msg := "no_nodes_to_copy_plugin_from",
reason := not_found
reason := plugin_not_found
}},
emqx_plugins:ensure_installed("nonexisting")
),