]> granicus.if.org Git - ejabberd/commitdiff
Don't crash when attempt to get an option for unknown virtual host
authorEvgeny Khramtsov <ekhramtsov@process-one.net>
Fri, 12 Jul 2019 10:59:33 +0000 (13:59 +0300)
committerEvgeny Khramtsov <ekhramtsov@process-one.net>
Fri, 12 Jul 2019 10:59:33 +0000 (13:59 +0300)
Log a warning instead and retry with a global scope

src/ejabberd_config.erl

index 59b8e4fc9491d43814ffee5d8e7f618f3689e903..f6f1a192b457163b0b4711ee11cb9156c915e123 100644 (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) ->