From f0c0e4a6fc94268b9acde3367a8ddff1cd912138 Mon Sep 17 00:00:00 2001 From: Evgeny Khramtsov Date: Fri, 12 Jul 2019 13:59:33 +0300 Subject: [PATCH] Don't crash when attempt to get an option for unknown virtual host Log a warning instead and retry with a global scope --- src/ejabberd_config.erl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ejabberd_config.erl b/src/ejabberd_config.erl index 59b8e4fc9..f6f1a192b 100644 --- a/src/ejabberd_config.erl +++ b/src/ejabberd_config.erl @@ -149,12 +149,21 @@ get_option(Opt, Default) -> -spec get_option(option()) -> term(). get_option(Opt) when is_atom(Opt) -> get_option({Opt, global}); -get_option(Opt) -> +get_option({O, Host} = Opt) -> Tab = case get_tmp_config() of undefined -> ejabberd_options; T -> T end, - ets:lookup_element(Tab, Opt, 2). + try ets:lookup_element(Tab, Opt, 2) + catch ?EX_RULE(error, badarg, St) when Host /= global -> + StackTrace = ?EX_STACK(St), + Val = get_option({O, global}), + ?WARNING_MSG("Option '~s' is not defined for virtual host '~s'. " + "This is a bug, please report it with the following " + "stacktrace included:~n** ~s", + [O, Host, misc:format_exception(2, error, badarg, StackTrace)]), + Val + end. -spec set_option(option(), term()) -> ok. set_option(Opt, Val) when is_atom(Opt) ->