Merge pull request #13419 from zhongwencool/port-pr

Port: some minor bug fixes from master
This commit is contained in:
zhongwencool 2024-07-06 14:42:51 +08:00 committed by GitHub
commit 29d7a511f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 50 additions and 13 deletions

View File

@ -890,7 +890,7 @@ fields("ws_opts") ->
)}, )},
{"max_frame_size", {"max_frame_size",
sc( sc(
hoconsc:union([infinity, integer()]), hoconsc:union([infinity, pos_integer()]),
#{ #{
default => infinity, default => infinity,
desc => ?DESC(fields_ws_opts_max_frame_size) desc => ?DESC(fields_ws_opts_max_frame_size)
@ -970,7 +970,7 @@ fields("tcp_opts") ->
[ [
{"active_n", {"active_n",
sc( sc(
integer(), non_neg_integer(),
#{ #{
default => 100, default => 100,
desc => ?DESC(fields_tcp_opts_active_n) desc => ?DESC(fields_tcp_opts_active_n)

View File

@ -237,6 +237,12 @@ load_config(Bin, Opts) when is_binary(Bin) ->
case hocon:binary(Bin) of case hocon:binary(Bin) of
{ok, RawConf} -> {ok, RawConf} ->
load_config_from_raw(RawConf, Opts); load_config_from_raw(RawConf, Opts);
%% Type is scan_error, parse_error...
{error, {Type, Meta = #{reason := Reason}}} ->
{error, Meta#{
reason => unicode:characters_to_binary(Reason),
type => Type
}};
{error, Reason} -> {error, Reason} ->
{error, Reason} {error, Reason}
end. end.

View File

@ -364,10 +364,10 @@ configs(get, #{query_string := QueryStr, headers := Headers}, _Req) ->
{error, _} = Error -> {400, #{code => 'INVALID_ACCEPT', message => ?ERR_MSG(Error)}} {error, _} = Error -> {400, #{code => 'INVALID_ACCEPT', message => ?ERR_MSG(Error)}}
end; end;
configs(put, #{body := Conf, query_string := #{<<"mode">> := Mode} = QS}, _Req) -> configs(put, #{body := Conf, query_string := #{<<"mode">> := Mode} = QS}, _Req) ->
IngnoreReadonly = maps:get(<<"ignore_readonly">>, QS, false), IgnoreReadonly = maps:get(<<"ignore_readonly">>, QS, false),
case case
emqx_conf_cli:load_config(Conf, #{ emqx_conf_cli:load_config(Conf, #{
mode => Mode, log => none, ignore_readonly => IngnoreReadonly mode => Mode, log => none, ignore_readonly => IgnoreReadonly
}) })
of of
ok -> ok ->

View File

@ -310,7 +310,7 @@ t_configs_key(_Config) ->
ReadOnlyBin = iolist_to_binary(hocon_pp:do(ReadOnlyConf, #{})), ReadOnlyBin = iolist_to_binary(hocon_pp:do(ReadOnlyConf, #{})),
{error, ReadOnlyError} = update_configs_with_binary(ReadOnlyBin), {error, ReadOnlyError} = update_configs_with_binary(ReadOnlyBin),
?assertEqual(<<"{\"errors\":\"Cannot update read-only key 'cluster'.\"}">>, ReadOnlyError), ?assertEqual(<<"{\"errors\":\"Cannot update read-only key 'cluster'.\"}">>, ReadOnlyError),
?assertMatch({ok, <<>>}, update_configs_with_binary(ReadOnlyBin, _InogreReadonly = true)), ?assertMatch({ok, <<>>}, update_configs_with_binary(ReadOnlyBin, _IgnoreReadonly = true)),
ok. ok.
t_get_configs_in_different_accept(_Config) -> t_get_configs_in_different_accept(_Config) ->
@ -443,13 +443,38 @@ t_create_webhook_v1_bridges_api(Config) ->
ok. ok.
t_config_update_parse_error(_Config) -> t_config_update_parse_error(_Config) ->
BadHoconList = [
<<"not an object">>,
<<"a = \"tlsv1\"\"\"3e-01">>
],
lists:map(
fun(BadHocon) ->
{error, ParseError} = update_configs_with_binary(BadHocon),
?assertMatch( ?assertMatch(
{error, <<"{\"errors\":\"{parse_error,", _/binary>>}, #{
update_configs_with_binary(<<"not an object">>) <<"errors">> :=
#{
<<"line">> := 1,
<<"reason">> := _,
<<"type">> := <<"parse_error">>
}
},
emqx_utils_json:decode(ParseError)
)
end,
BadHoconList
), ),
{error, ScanError} = update_configs_with_binary(<<"a=测试"/utf8>>),
?assertMatch( ?assertMatch(
{error, <<"{\"errors\":\"{parse_error,", _/binary>>}, #{
update_configs_with_binary(<<"a = \"tlsv1\"\"\"3e-01">>) <<"errors">> := #{
<<"line">> := 1,
<<"reason">> := _,
<<"type">> := <<"scan_error">>
}
},
emqx_utils_json:decode(ScanError)
). ).
t_config_update_unknown_root(_Config) -> t_config_update_unknown_root(_Config) ->

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{application, emqx_modules, [ {application, emqx_modules, [
{description, "EMQX Modules"}, {description, "EMQX Modules"},
{vsn, "5.0.26"}, {vsn, "5.0.27"},
{modules, []}, {modules, []},
{applications, [kernel, stdlib, emqx, emqx_ctl, observer_cli]}, {applications, [kernel, stdlib, emqx, emqx_ctl, observer_cli]},
{mod, {emqx_modules_app, []}}, {mod, {emqx_modules_app, []}},

View File

@ -46,8 +46,13 @@ cmd(["load", Mod]) ->
Nodes -> Nodes ->
case emqx_utils:safe_to_existing_atom(Mod) of case emqx_utils:safe_to_existing_atom(Mod) of
{ok, Module} -> {ok, Module} ->
case code:get_object_code(Module) of
error ->
emqx_ctl:print("Module(~s)'s object code not found~n", [Mod]);
_ ->
Res = recon:remote_load(Nodes, Module), Res = recon:remote_load(Nodes, Module),
emqx_ctl:print("Loaded ~p module on ~p: ~p~n", [Module, Nodes, Res]); emqx_ctl:print("Loaded ~p module on ~p: ~p~n", [Module, Nodes, Res])
end;
{error, Reason} -> {error, Reason} ->
emqx_ctl:print("Module(~s) not found: ~p~n", [Mod, Reason]) emqx_ctl:print("Module(~s) not found: ~p~n", [Mod, Reason])
end end

View File

@ -0,0 +1 @@
Fix garbled hints in crash log message when calling /configs API