fix: make static_check happy

This commit is contained in:
JimMoen 2024-05-20 18:46:41 +08:00
parent 3ce091e9d7
commit 87b3b214b9
No known key found for this signature in database
5 changed files with 30 additions and 25 deletions

View File

@ -64,6 +64,7 @@
{emqx_node_rebalance_status,2}.
{emqx_persistent_session_ds,1}.
{emqx_plugins,1}.
{emqx_plugins,2}.
{emqx_prometheus,1}.
{emqx_prometheus,2}.
{emqx_resource,1}.

View File

@ -21,6 +21,8 @@
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx_plugins/include/emqx_plugins.hrl").
-dialyzer({no_match, [format_plugin_avsc_and_i18n/1]}).
-export([
api_spec/0,
fields/1,
@ -534,7 +536,7 @@ update_boot_order(post, #{bindings := #{name := Name}, body := Body}) ->
{error, Reason} ->
{400, #{code => 'BAD_POSITION', message => Reason}};
Position ->
case emqx_plugins:ensure_enabled(Name, Position, _ConfLocation = global) of
case emqx_plugins:ensure_enabled(Name, Position, global) of
ok ->
{204};
{error, Reason} ->
@ -694,16 +696,12 @@ aggregate_status([{Node, Plugins} | List], Acc) ->
),
aggregate_status(List, NewAcc).
-if(?EMQX_RELEASE_EDITION == ee).
format_plugin_avsc_and_i18n(NameVsn) ->
case emqx_release:edition() of
ee ->
#{
avsc => try_read_file(fun() -> emqx_plugins:plugin_avsc(NameVsn) end),
i18n => try_read_file(fun() -> emqx_plugins:plugin_i18n(NameVsn) end)
};
ce ->
#{avsc => null, i18n => null}
end.
#{
avsc => try_read_file(fun() -> emqx_plugins:plugin_avsc(NameVsn) end),
i18n => try_read_file(fun() -> emqx_plugins:plugin_i18n(NameVsn) end)
}.
try_read_file(Fun) ->
case Fun() of
@ -711,6 +709,11 @@ try_read_file(Fun) ->
_ -> null
end.
-else.
format_plugin_avsc_and_i18n(_NameVsn) ->
#{avsc => null, i18n => null}.
-endif.
% running_status: running loaded, stopped
%% config_status: not_configured disable enable
plugin_status(#{running_status := running}) -> running;

View File

@ -152,8 +152,10 @@ make_name_vsn_string(Name, Vsn) ->
-spec ensure_installed() -> ok.
ensure_installed() ->
Fun = fun(#{name_vsn := NameVsn}) ->
ensure_installed(NameVsn),
[]
case ensure_installed(NameVsn) of
ok -> [];
{error, Reason} -> [{NameVsn, Reason}]
end
end,
ok = for_plugins(Fun).
@ -169,8 +171,8 @@ ensure_installed(NameVsn) ->
case ensure_exists_and_installed(NameVsn) of
ok ->
maybe_post_op_after_installed(NameVsn);
_ ->
ok
{error, _Reason} = Err ->
Err
end
end.
@ -280,8 +282,10 @@ ensure_started(NameVsn) ->
-spec ensure_stopped() -> ok.
ensure_stopped() ->
Fun = fun(#{name_vsn := NameVsn, enable := true}) ->
ensure_stopped(NameVsn),
[]
case ensure_stopped(NameVsn) of
ok -> [];
{error, Reason} -> [{NameVsn, Reason}]
end
end,
ok = for_plugins(Fun).
@ -314,7 +318,7 @@ get_config(NameVsn, #{format := ?CONFIG_FORMAT_AVRO}) ->
{ok, _AvroJson} = Res -> Res;
{error, _Reason} = Err -> Err
end;
get_config(NameVsn, Options = #{format := ?CONFIG_FORMAT_MAP}) ->
get_config(NameVsn, #{format := ?CONFIG_FORMAT_MAP} = Options) ->
get_config(NameVsn, Options, #{}).
%% Present default config value only in map format.
@ -714,7 +718,7 @@ ensure_exists_and_installed(NameVsn) ->
case get_tar(NameVsn) of
{ok, TarContent} ->
ok = file:write_file(pkg_file_path(NameVsn), TarContent),
ok = do_ensure_installed(NameVsn);
do_ensure_installed(NameVsn);
_ ->
%% If not, try to get it from the cluster.
do_get_from_cluster(NameVsn)
@ -733,13 +737,13 @@ do_get_from_cluster(NameVsn) ->
name_vsn => NameVsn,
node_errors => NodeErrors
}),
{error, plugin_not_found};
{error, #{reason => not_found, name_vsn => NameVsn}};
{error, _} ->
?SLOG(error, #{
msg => "no_nodes_to_copy_plugin_from",
name_vsn => NameVsn
}),
{error, plugin_not_found}
{error, #{reason => not_found, name_vsn => NameVsn}}
end.
get_from_any_node([], _NameVsn, Errors) ->
@ -763,7 +767,7 @@ get_avro_config_from_any_node([Node | T], NameVsn, Errors) ->
{ok, _} = Res ->
Res;
Err ->
get_from_any_node(T, NameVsn, [{Node, Err} | Errors])
get_avro_config_from_any_node(T, NameVsn, [{Node, Err} | Errors])
end.
plugins_readme(NameVsn, #{fill_readme := true}, Info) ->

View File

@ -20,7 +20,6 @@
-export([
introduced_in/0,
deprecated_since/0,
get_tar/3
]).
@ -31,9 +30,6 @@
introduced_in() ->
"5.0.21".
deprecated_since() ->
"5.7.0".
-spec get_tar(node(), name_vsn(), timeout()) -> {ok, binary()} | {error, any}.
get_tar(Node, NameVsn, Timeout) ->
rpc:call(Node, emqx_plugins, get_tar, [NameVsn], Timeout).

View File

@ -35,5 +35,6 @@ introduced_in() ->
get_tar(Node, NameVsn, Timeout) ->
rpc:call(Node, emqx_plugins, get_tar, [NameVsn], Timeout).
-spec get_config(node(), name_vsn(), map(), any(), timeout()) -> {ok, any()} | {error, any()}.
get_config(Node, NameVsn, Opts, Default, Timeout) ->
rpc:call(Node, emqx_plugins, get_config, [NameVsn, Opts, Default], Timeout).