Merge pull request #13236 from zhongwencool/bug-schema-validation

fix: some minor bug fixes
This commit is contained in:
zhongwencool 2024-06-15 06:40:28 +08:00 committed by GitHub
commit d433fc7c30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 48 additions and 12 deletions

View File

@ -885,7 +885,7 @@ fields("ws_opts") ->
)},
{"max_frame_size",
sc(
hoconsc:union([infinity, integer()]),
hoconsc:union([infinity, pos_integer()]),
#{
default => infinity,
desc => ?DESC(fields_ws_opts_max_frame_size)
@ -965,7 +965,7 @@ fields("tcp_opts") ->
[
{"active_n",
sc(
integer(),
non_neg_integer(),
#{
default => 100,
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
{ok, RawConf} ->
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}
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)}}
end;
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
emqx_conf_cli:load_config(Conf, #{
mode => Mode, log => none, ignore_readonly => IngnoreReadonly
mode => Mode, log => none, ignore_readonly => IgnoreReadonly
})
of
ok ->

View File

@ -310,7 +310,7 @@ t_configs_key(_Config) ->
ReadOnlyBin = iolist_to_binary(hocon_pp:do(ReadOnlyConf, #{})),
{error, ReadOnlyError} = update_configs_with_binary(ReadOnlyBin),
?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.
t_get_configs_in_different_accept(_Config) ->
@ -444,13 +444,38 @@ t_create_webhook_v1_bridges_api(Config) ->
ok.
t_config_update_parse_error(_Config) ->
?assertMatch(
{error, <<"{\"errors\":\"{parse_error,", _/binary>>},
update_configs_with_binary(<<"not an object">>)
BadHoconList = [
<<"not an object">>,
<<"a = \"tlsv1\"\"\"3e-01">>
],
lists:map(
fun(BadHocon) ->
{error, ParseError} = update_configs_with_binary(BadHocon),
?assertMatch(
#{
<<"errors">> :=
#{
<<"line">> := 1,
<<"reason">> := _,
<<"type">> := <<"parse_error">>
}
},
emqx_utils_json:decode(ParseError)
)
end,
BadHoconList
),
{error, ScanError} = update_configs_with_binary(<<"a=测试"/utf8>>),
?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) ->

View File

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