diff options
Diffstat (limited to 'src/gen_mod.erl')
-rw-r--r-- | src/gen_mod.erl | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/gen_mod.erl b/src/gen_mod.erl index c15b50443..d225beeff 100644 --- a/src/gen_mod.erl +++ b/src/gen_mod.erl @@ -58,6 +58,7 @@ -include("logger.hrl"). -include_lib("stdlib/include/ms_transform.hrl"). +-include("ejabberd_stacktrace.hrl"). -record(ejabberd_module, {module_host = {undefined, <<"">>} :: {atom(), binary()}, @@ -67,7 +68,7 @@ -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()]. @@ -217,8 +218,8 @@ start_module(Host, Module, Opts0, Order, NeedValidation) -> {ok, Pid} when is_pid(Pid) -> {ok, Pid}; Err -> erlang:error({bad_return, Module, Err}) end - catch Class:Reason -> - StackTrace = erlang:get_stacktrace(), + catch ?EX_RULE(Class, Reason, Stack) -> + StackTrace = ?EX_STACK(Stack), ets:delete(ejabberd_modules, {Module, Host}), ErrorText = format_module_error( Module, start, 2, @@ -282,8 +283,8 @@ reload_module(Host, Module, NewOpts, OldOpts, Order) -> {ok, Pid} when is_pid(Pid) -> {ok, Pid}; Err -> erlang:error({bad_return, Module, Err}) end - catch Class:Reason -> - StackTrace = erlang:get_stacktrace(), + catch ?EX_RULE(Class, Reason, Stack) -> + StackTrace = ?EX_STACK(Stack), ErrorText = format_module_error( Module, reload, 3, NewOpts, Class, Reason, @@ -548,12 +549,12 @@ validate_opts(Host, Module, Opts0) -> _:{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': " @@ -620,7 +621,7 @@ validate_opt(Opt, Val, VFun) -> NewVal -> [{Opt, NewVal}] catch {invalid_syntax, Error} -> err_invalid_option(Opt, Val, Error); - _:_ -> + _:R when R /= undef -> err_invalid_option(Opt, Val) end. @@ -730,6 +731,9 @@ format_module_error(Module, Fun, Arity, Opts, Class, Reason, St) -> "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" |