25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Don't crash when attempt to get an option for unknown virtual host

Log a warning instead and retry with a global scope
This commit is contained in:
Evgeny Khramtsov 2019-07-12 13:59:33 +03:00
parent 696c64064b
commit f0c0e4a6fc

View File

@ -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) ->