]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Specify failure reason clearly
authorVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 11 Jul 2024 13:03:40 +0000 (14:03 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 11 Jul 2024 13:06:50 +0000 (14:06 +0100)
src/libserver/cfg_utils.cxx
src/rspamd.c

index bcd26d59c4d4c14ea5e84ac95a79806b40e35272..afa4009ccf68019bb06a8f36f763eab91982c6ee 100644 (file)
@@ -57,7 +57,7 @@
 #ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
 #endif
-#include <math.h>
+#include <cmath>
 #include "libserver/composites/composites.h"
 
 #include "blas-config.h"
@@ -69,6 +69,7 @@
 #include "cxx/util.hxx"
 #include "frozen/unordered_map.h"
 #include "frozen/string.h"
+#include "contrib/expected/expected.hpp"
 #include "contrib/ankerl/unordered_dense.h"
 
 #define DEFAULT_SCORE 10.0
@@ -826,8 +827,7 @@ gboolean
 rspamd_config_post_load(struct rspamd_config *cfg,
                                                enum rspamd_post_load_options opts)
 {
-
-       auto ret = TRUE;
+       auto ret = tl::expected<void, std::string>{};
 
        rspamd_adjust_clocks_resolution(cfg);
        rspamd_logger_configure_modules(cfg->debug_modules);
@@ -867,14 +867,15 @@ rspamd_config_post_load(struct rspamd_config *cfg,
                        else {
                                if (opts & RSPAMD_CONFIG_INIT_VALIDATE) {
                                        msg_err_config("no url_tld option has been specified");
-                                       ret = FALSE;
+                                       ret = tl::make_unexpected(std::string{"no url_tld option has been specified"});
                                }
                        }
                }
                else {
                        if (access(cfg->tld_file, R_OK) == -1) {
                                if (opts & RSPAMD_CONFIG_INIT_VALIDATE) {
-                                       ret = FALSE;
+                                       ret = tl::make_unexpected(fmt::format("cannot access tld file {}: {}",
+                                                                                                                 cfg->tld_file, strerror(errno)));
                                        msg_err_config("cannot access tld file %s: %s", cfg->tld_file,
                                                                   strerror(errno));
                                }
@@ -905,13 +906,17 @@ rspamd_config_post_load(struct rspamd_config *cfg,
        if (!rspamd_config_parse_log_format(cfg)) {
                msg_err_config("cannot parse log format, task logging will not be available");
                if (opts & RSPAMD_CONFIG_INIT_VALIDATE) {
-                       ret = FALSE;
+                       ret = tl::make_unexpected(std::string{"cannot parse log format"});
                }
        }
 
        if (opts & RSPAMD_CONFIG_INIT_SYMCACHE) {
                /* Init config cache */
-               ret = rspamd_symcache_init(cfg->cache) && ret;
+               auto symcache_ret = rspamd_symcache_init(cfg->cache);
+
+               if (!symcache_ret) {
+                       ret = tl::make_unexpected(std::string{"symcache init failed"});
+               }
 
                /* Init re cache */
                rspamd_re_cache_init(cfg->re_cache, cfg);
@@ -959,7 +964,11 @@ rspamd_config_post_load(struct rspamd_config *cfg,
                                                        " Rspamd features will be broken");
                }
 
-               ret = rspamd_symcache_validate(cfg->cache, cfg, FALSE) && ret;
+               auto val_ret = rspamd_symcache_validate(cfg->cache, cfg, FALSE);
+
+               if (!val_ret) {
+                       ret = tl::make_unexpected(std::string{"symcache validation failed"});
+               }
        }
 
        if (opts & RSPAMD_CONFIG_INIT_POST_LOAD_LUA) {
@@ -970,7 +979,14 @@ rspamd_config_post_load(struct rspamd_config *cfg,
                rspamd_map_preload(cfg);
        }
 
-       return ret;
+       if (ret) {
+               return true;
+       }
+       else {
+               msg_err_config("error on post-init stage: %s", ret.error().c_str());
+
+               return false;
+       }
 }
 
 struct rspamd_classifier_config *
index 117f3b9950e0aa98143c3d089fe7ee7b9c8ef1fa..b6c361cb28b66e36cf5b8c4cd38369dca964e4f9 100644 (file)
@@ -979,12 +979,16 @@ load_rspamd_config(struct rspamd_main *rspamd_main,
 
                if (init_modules) {
                        if (!rspamd_init_filters(cfg, reload, false)) {
+                               msg_err_main("init filters failed");
+
                                return FALSE;
                        }
                }
 
                /* Do post-load actions */
                if (!rspamd_config_post_load(cfg, opts)) {
+                       msg_err_main("post load failed");
+
                        return FALSE;
                }
        }