]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Fix errors reporting on learn errors
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 14 Jul 2016 11:29:54 +0000 (12:29 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 14 Jul 2016 11:29:54 +0000 (12:29 +0100)
src/libserver/task.c
src/libstat/stat_process.c

index 7b4970943359182ae812f5bde87fc3d155f854f2..121e1bc64b76b2c1012db38e8c27a81340310971 100644 (file)
@@ -617,6 +617,14 @@ rspamd_task_process (struct rspamd_task *task, guint stages)
                                                task->cfg->lua_state, task->classifier,
                                                st, &stat_error)) {
 
+                                       if (stat_error == NULL) {
+                                               g_set_error (&stat_error,
+                                                               g_quark_from_static_string ("stat"), 500,
+                                                               "Unknown statistics error");
+                                       }
+
+                                       msg_err_task ("learn error: %e", stat_error);
+
                                        if (!(task->flags & RSPAMD_TASK_FLAG_LEARN_AUTO)) {
                                                task->err = stat_error;
                                        }
@@ -624,7 +632,6 @@ rspamd_task_process (struct rspamd_task *task, guint stages)
                                                g_error_free (stat_error);
                                        }
 
-                                       msg_err_task ("learn error: %e", stat_error);
                                        task->processed_stages |= RSPAMD_TASK_STAGE_DONE;
                                }
                        }
index cca676288c183bc2bc93aae1fe05238b82108e0d..49585af66b47135784c1baa446d683d8772bc342 100644 (file)
@@ -389,7 +389,7 @@ rspamd_stat_cache_check (struct rspamd_stat_ctx *st_ctx,
                 GError **err)
 {
        rspamd_learn_t learn_res = RSPAMD_LEARN_OK;
-       struct rspamd_classifier *cl;
+       struct rspamd_classifier *cl, *sel = NULL;
        gpointer rt;
        guint i;
 
@@ -403,8 +403,10 @@ rspamd_stat_cache_check (struct rspamd_stat_ctx *st_ctx,
                        continue;
                }
 
-               if (cl->cache && cl->cachecf) {
-                       rt = cl->cache->runtime (task, cl->cachecf, FALSE);
+               sel = cl;
+
+               if (sel->cache && sel->cachecf) {
+                       rt = cl->cache->runtime (task, sel->cachecf, FALSE);
                        learn_res = cl->cache->check (task, spam, rt);
                }
 
@@ -423,6 +425,18 @@ rspamd_stat_cache_check (struct rspamd_stat_ctx *st_ctx,
                }
        }
 
+       if (sel == NULL) {
+               if (classifier) {
+                       g_set_error (err, rspamd_stat_quark (), 404, "cannot find classifier "
+                                       "with name %s", classifier);
+               }
+               else {
+                       g_set_error (err, rspamd_stat_quark (), 404, "no classifiers defined");
+               }
+
+               return FALSE;
+       }
+
        return TRUE;
 }
 
@@ -433,7 +447,7 @@ rspamd_stat_classifiers_learn (struct rspamd_stat_ctx *st_ctx,
                 gboolean spam,
                 GError **err)
 {
-       struct rspamd_classifier *cl;
+       struct rspamd_classifier *cl, *sel = NULL;
        guint i;
        gboolean learned = FALSE, too_small = FALSE, too_large = FALSE,
                        conditionally_skipped = FALSE;
@@ -453,6 +467,8 @@ rspamd_stat_classifiers_learn (struct rspamd_stat_ctx *st_ctx,
                        continue;
                }
 
+               sel = cl;
+
                /* Now check max and min tokens */
                if (cl->cfg->min_tokens > 0 && task->tokens->len < cl->cfg->min_tokens) {
                        msg_info_task (
@@ -529,6 +545,18 @@ rspamd_stat_classifiers_learn (struct rspamd_stat_ctx *st_ctx,
                }
        }
 
+       if (sel == NULL) {
+               if (classifier) {
+                       g_set_error (err, rspamd_stat_quark (), 404, "cannot find classifier "
+                                       "with name %s", classifier);
+               }
+               else {
+                       g_set_error (err, rspamd_stat_quark (), 404, "no classifiers defined");
+               }
+
+               return FALSE;
+       }
+
        if (!learned && err && *err == NULL) {
                if (too_large) {
                        g_set_error (err, rspamd_stat_quark (), 400,
@@ -568,7 +596,7 @@ rspamd_stat_backends_learn (struct rspamd_stat_ctx *st_ctx,
                 gboolean spam,
                 GError **err)
 {
-       struct rspamd_classifier *cl;
+       struct rspamd_classifier *cl, *sel = NULL;
        struct rspamd_statfile *st;
        gpointer bk_run;
        guint i, j;
@@ -584,6 +612,8 @@ rspamd_stat_backends_learn (struct rspamd_stat_ctx *st_ctx,
                        continue;
                }
 
+               sel = cl;
+
                for (j = 0; j < cl->statfiles_ids->len; j ++) {
                        id = g_array_index (cl->statfiles_ids, gint, j);
                        st = g_ptr_array_index (st_ctx->statfiles, id);
@@ -622,6 +652,18 @@ rspamd_stat_backends_learn (struct rspamd_stat_ctx *st_ctx,
                }
        }
 
+       if (sel == NULL) {
+               if (classifier) {
+                       g_set_error (err, rspamd_stat_quark (), 404, "cannot find classifier "
+                                       "with name %s", classifier);
+               }
+               else {
+                       g_set_error (err, rspamd_stat_quark (), 404, "no classifiers defined");
+               }
+
+               return FALSE;
+       }
+
        return res;
 }