?ERROR_MSG("Invalid value for "
"option '~s' (~s): ~s",
[Opt, Error,
- misc:format_val(Val)]),
+ misc:format_val({yaml, Val})]),
erlang:error(invalid_option);
_:_ ->
?ERROR_MSG("Invalid value for "
"option '~s': ~s",
- [Opt, misc:format_val(Val)]),
+ [Opt, misc:format_val({yaml, Val})]),
erlang:error(invalid_option)
end;
_ ->
-type opts() :: [{atom(), any()}].
-type db_type() :: atom().
--callback start(binary(), opts()) -> ok | {ok, pid()}.
+-callback start(binary(), opts()) -> ok | {ok, pid()} | {error, term()}.
-callback stop(binary()) -> any().
-callback reload(binary(), opts(), opts()) -> ok | {ok, pid()}.
-callback mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()].
_:{invalid_option, Opt, Val} ->
ErrTxt = io_lib:format("Invalid value for option '~s' of "
"module ~s: ~s",
- [Opt, Module, misc:format_val(Val)]),
+ [Opt, Module, misc:format_val({yaml, Val})]),
module_error(ErrTxt);
_:{invalid_option, Opt, Val, Reason} ->
ErrTxt = io_lib:format("Invalid value for option '~s' of "
"module ~s (~s): ~s",
- [Opt, Module, Reason, misc:format_val(Val)]),
+ [Opt, Module, Reason, misc:format_val({yaml, Val})]),
module_error(ErrTxt);
_:{unknown_option, Opt, []} ->
ErrTxt = io_lib:format("Unknown option '~s' of module '~s': "
"it doesn't export ~s/~B callback: "
"is it really an ejabberd module?",
[Fun, Module, Fun, Arity]);
+ {error, {bad_return, Module, {error, _} = Err}} ->
+ io_lib:format("Failed to ~s module ~s: ~s",
+ [Fun, Module, misc:format_val(Err)]);
{error, {bad_return, Module, Ret}} ->
io_lib:format("Module ~s returned unexpected value from ~s/~B:~n"
"** Error: ~p~n"
end, L1).
-spec format_val(any()) -> iodata().
+format_val({yaml, S}) when is_integer(S); is_binary(S); is_atom(S) ->
+ format_val(S);
+format_val({yaml, YAML}) ->
+ S = try fast_yaml:encode(YAML)
+ catch _:_ -> YAML
+ end,
+ format_val(S);
format_val(I) when is_integer(I) ->
integer_to_list(I);
-format_val(S) when is_binary(S) ->
- <<$", S/binary, $">>;
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])
+format_val(Term) ->
+ S = try iolist_to_binary(Term)
+ catch _:_ -> list_to_binary(io_lib:format("~p", [Term]))
+ end,
+ case binary:match(S, <<"\n">>) of
+ nomatch -> S;
+ _ -> [io_lib:nl(), S]
end.
-spec cancel_timer(reference()) -> ok.