fix: imporve hocon check failed error
This commit is contained in:
parent
1fc7bfa4f5
commit
55f8f7277d
|
@ -31,8 +31,8 @@
|
||||||
|
|
||||||
-export([format/2]).
|
-export([format/2]).
|
||||||
|
|
||||||
%% For CLI outputs
|
%% For CLI HTTP API outputs
|
||||||
-export([best_effort_json/1]).
|
-export([best_effort_json/1, best_effort_json/2]).
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include_lib("proper/include/proper.hrl").
|
-include_lib("proper/include/proper.hrl").
|
||||||
|
@ -62,9 +62,11 @@
|
||||||
%% The JSON object is pretty-printed.
|
%% The JSON object is pretty-printed.
|
||||||
%% NOTE: do not use this function for logging.
|
%% NOTE: do not use this function for logging.
|
||||||
best_effort_json(Input) ->
|
best_effort_json(Input) ->
|
||||||
|
best_effort_json(Input, [space, {indent, 4}]).
|
||||||
|
best_effort_json(Input, Opts) ->
|
||||||
Config = #{depth => unlimited, single_line => true},
|
Config = #{depth => unlimited, single_line => true},
|
||||||
JsonReady = best_effort_json_obj(Input, Config),
|
JsonReady = best_effort_json_obj(Input, Config),
|
||||||
jsx:encode(JsonReady, [space, {indent, 4}]).
|
jsx:encode(JsonReady, Opts).
|
||||||
|
|
||||||
-spec format(logger:log_event(), config()) -> iodata().
|
-spec format(logger:log_event(), config()) -> iodata().
|
||||||
format(#{level := Level, msg := Msg, meta := Meta}, Config0) when is_map(Config0) ->
|
format(#{level := Level, msg := Msg, meta := Meta}, Config0) when is_map(Config0) ->
|
||||||
|
|
|
@ -408,7 +408,9 @@ trans_description(Spec, Hocon) ->
|
||||||
end,
|
end,
|
||||||
case Desc of
|
case Desc of
|
||||||
undefined -> Spec;
|
undefined -> Spec;
|
||||||
Desc -> Spec#{description => Desc}
|
Desc ->
|
||||||
|
Desc1 = binary:replace(Desc, [<<"</br>\n">>, <<"\n">>], <<"</br>">>, [global]),
|
||||||
|
Spec#{description => Desc1}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_i18n(Key, Struct, Default) ->
|
get_i18n(Key, Struct, Default) ->
|
||||||
|
@ -813,17 +815,15 @@ schema_converter(Options) ->
|
||||||
|
|
||||||
serialize_hocon_error_msg({_Schema, Errors}) ->
|
serialize_hocon_error_msg({_Schema, Errors}) ->
|
||||||
Msg = lists:map(fun hocon_error/1, Errors),
|
Msg = lists:map(fun hocon_error/1, Errors),
|
||||||
iolist_to_binary(string:join(Msg, ","));
|
iolist_to_binary(Msg);
|
||||||
serialize_hocon_error_msg(Error) ->
|
serialize_hocon_error_msg(Error) ->
|
||||||
iolist_to_binary(io_lib:format("~p", [Error])).
|
iolist_to_binary(io_lib:format("~p", [Error])).
|
||||||
|
|
||||||
hocon_error({validation_error, #{reason := #{exception := Exception}, path := Path}}) ->
|
hocon_error({validation_error, #{path := Path} = Error}) ->
|
||||||
io_lib:format("~ts: ~p", [sub_path(Path), Exception]);
|
Error1 = maps:without([path, stacktrace], Error),
|
||||||
hocon_error({validation_error, #{reason := Reason, path := Path, value := Value}}) ->
|
emqx_logger_jsonfmt:best_effort_json(Error1#{<<"path">> => sub_path(Path)}, []);
|
||||||
io_lib:format("~ts: ~p ~p", [sub_path(Path), Value, Reason]);
|
hocon_error({translation_error, #{value_path := Path} = Error}) ->
|
||||||
hocon_error({validation_error, #{reason := Reason, path := Path}}) ->
|
Error1 = maps:without([value_path, stacktrace], Error),
|
||||||
io_lib:format("~ts: ~p", [sub_path(Path), Reason]);
|
emqx_logger_jsonfmt:best_effort_json(Error1#{<<"path">> => sub_path(Path)}, []).
|
||||||
hocon_error({translation_error, #{reason := Reason, value_path := Path}}) ->
|
|
||||||
io_lib:format("~ts: ~p", [sub_path(Path), Reason]).
|
|
||||||
|
|
||||||
sub_path(Path) -> string:trim(Path, leading, "root.").
|
sub_path(Path) -> string:trim(Path, leading, "root.").
|
||||||
|
|
Loading…
Reference in New Issue