Better format invalid values when logging them
This commit is contained in:
parent
68d12017cc
commit
8c796ed027
|
@ -1078,14 +1078,15 @@ validate_opts(#state{opts = Opts} = State, ModOpts) ->
|
||||||
NewVal ->
|
NewVal ->
|
||||||
In#local_config{value = NewVal}
|
In#local_config{value = NewVal}
|
||||||
catch {invalid_syntax, Error} ->
|
catch {invalid_syntax, Error} ->
|
||||||
?ERROR_MSG("Invalid value '~p' for "
|
?ERROR_MSG("Invalid value for "
|
||||||
"option '~s': ~s",
|
"option '~s' (~s): ~s",
|
||||||
[Val, Opt, Error]),
|
[Opt, Error,
|
||||||
|
misc:format_val(Val)]),
|
||||||
erlang:error(invalid_option);
|
erlang:error(invalid_option);
|
||||||
_:_ ->
|
_:_ ->
|
||||||
?ERROR_MSG("Invalid value '~p' for "
|
?ERROR_MSG("Invalid value for "
|
||||||
"option '~s'",
|
"option '~s': ~s",
|
||||||
[Val, Opt]),
|
[Opt, misc:format_val(Val)]),
|
||||||
erlang:error(invalid_option)
|
erlang:error(invalid_option)
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
|
|
|
@ -546,12 +546,14 @@ validate_opts(Host, Module, Opts0) ->
|
||||||
[Module, Opt]),
|
[Module, Opt]),
|
||||||
module_error(ErrTxt);
|
module_error(ErrTxt);
|
||||||
_:{invalid_option, Opt, Val} ->
|
_:{invalid_option, Opt, Val} ->
|
||||||
ErrTxt = io_lib:format("Invalid value '~p' for option '~s' of "
|
ErrTxt = io_lib:format("Invalid value for option '~s' of "
|
||||||
"module '~s'", [Val, Opt, Module]),
|
"module ~s: ~s",
|
||||||
|
[Opt, Module, misc:format_val(Val)]),
|
||||||
module_error(ErrTxt);
|
module_error(ErrTxt);
|
||||||
_:{invalid_option, Opt, Val, Reason} ->
|
_:{invalid_option, Opt, Val, Reason} ->
|
||||||
ErrTxt = io_lib:format("Invalid value '~p' for option '~s' of "
|
ErrTxt = io_lib:format("Invalid value for option '~s' of "
|
||||||
"module '~s': ~s", [Val, Opt, Module, Reason]),
|
"module ~s (~s): ~s",
|
||||||
|
[Opt, Module, Reason, misc:format_val(Val)]),
|
||||||
module_error(ErrTxt);
|
module_error(ErrTxt);
|
||||||
_:{unknown_option, Opt, []} ->
|
_:{unknown_option, Opt, []} ->
|
||||||
ErrTxt = io_lib:format("Unknown option '~s' of module '~s': "
|
ErrTxt = io_lib:format("Unknown option '~s' of module '~s': "
|
||||||
|
|
15
src/misc.erl
15
src/misc.erl
|
@ -35,7 +35,8 @@
|
||||||
now_to_usec/1, usec_to_now/1, encode_pid/1, decode_pid/2,
|
now_to_usec/1, usec_to_now/1, encode_pid/1, decode_pid/2,
|
||||||
compile_exprs/2, join_atoms/2, try_read_file/1, get_descr/2,
|
compile_exprs/2, join_atoms/2, try_read_file/1, get_descr/2,
|
||||||
css_dir/0, img_dir/0, js_dir/0, msgs_dir/0, sql_dir/0,
|
css_dir/0, img_dir/0, js_dir/0, msgs_dir/0, sql_dir/0,
|
||||||
read_css/1, read_img/1, read_js/1, try_url/1, intersection/2]).
|
read_css/1, read_img/1, read_js/1, try_url/1, intersection/2,
|
||||||
|
format_val/1]).
|
||||||
|
|
||||||
%% Deprecated functions
|
%% Deprecated functions
|
||||||
-export([decode_base64/1, encode_base64/1]).
|
-export([decode_base64/1, encode_base64/1]).
|
||||||
|
@ -287,6 +288,18 @@ intersection(L1, L2) ->
|
||||||
lists:member(E, L2)
|
lists:member(E, L2)
|
||||||
end, L1).
|
end, L1).
|
||||||
|
|
||||||
|
-spec format_val(any()) -> iodata().
|
||||||
|
format_val(I) when is_integer(I) ->
|
||||||
|
integer_to_list(I);
|
||||||
|
format_val(S) when is_binary(S) ->
|
||||||
|
S;
|
||||||
|
format_val(B) when is_atom(B) ->
|
||||||
|
erlang:atom_to_binary(B, utf8);
|
||||||
|
format_val(YAML) ->
|
||||||
|
try [io_lib:nl(), fast_yaml:encode(YAML)]
|
||||||
|
catch _:_ -> io_lib:format("~p", [YAML])
|
||||||
|
end.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
Loading…
Reference in New Issue