aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-09-28 15:34:25 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-09-28 15:34:43 +0100
commiteb0ec636b6545843d135379351d2a7280ee6e397 (patch)
treebeaf97c1aa4dae66072e7989f57ce9ed50c30a7d /src
parent0d66719b5e7fea0c966d83565884f6c6a0465d2a (diff)
downloadrspamd-eb0ec636b6545843d135379351d2a7280ee6e397.tar.gz
rspamd-eb0ec636b6545843d135379351d2a7280ee6e397.zip
[Minor] Improve learn error reporting
Diffstat (limited to 'src')
-rw-r--r--src/libstat/stat_process.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c
index 2c77942b6..2ebc8f599 100644
--- a/src/libstat/stat_process.c
+++ b/src/libstat/stat_process.c
@@ -339,14 +339,12 @@ rspamd_stat_backends_process (struct rspamd_stat_ctx *st_ctx,
{
guint i;
struct rspamd_statfile *st;
- struct rspamd_classifier *cl;
gpointer bk_run;
g_assert (task->stat_runtimes != NULL);
for (i = 0; i < st_ctx->statfiles->len; i++) {
st = g_ptr_array_index (st_ctx->statfiles, i);
- cl = st->classifier;
bk_run = g_ptr_array_index (task->stat_runtimes, i);
if (bk_run != NULL) {
@@ -677,7 +675,7 @@ rspamd_stat_backends_learn (struct rspamd_stat_ctx *st_ctx,
gpointer bk_run;
guint i, j;
gint id;
- gboolean res = FALSE;
+ gboolean res = FALSE, backend_found = FALSE;
for (i = 0; i < st_ctx->classifiers->len; i ++) {
cl = g_ptr_array_index (st_ctx->classifiers, i);
@@ -714,11 +712,14 @@ rspamd_stat_backends_learn (struct rspamd_stat_ctx *st_ctx,
goto end;
}
- msg_warn_task ("no runtime for backend %s; classifier %s; symbol %s",
+ msg_debug_task ("no runtime for backend %s; classifier %s; symbol %s",
st->backend->name, cl->cfg->name, st->stcf->symbol);
continue;
}
+ /* We set sel merely when we have runtime */
+ backend_found = TRUE;
+
if (!(task->flags & RSPAMD_TASK_FLAG_UNLEARN)) {
if (!!spam != !!st->stcf->is_spam) {
/* If we are not unlearning, then do not touch another class */
@@ -748,26 +749,36 @@ rspamd_stat_backends_learn (struct rspamd_stat_ctx *st_ctx,
}
end:
- if (!res && err) {
- return res;
- }
- if (!res && 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");
+ if (!res) {
+ if (err && *err) {
+ /* Error has been set already */
+ return res;
}
- return FALSE;
- }
+ 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");
+ }
- if (!res) {
- g_set_error (err, rspamd_stat_quark (), 404, "cannot find statfile "
- "backend to learn %s in %s", spam ? "spam" : "ham",
- classifier ? classifier : "default classifier");
+ return FALSE;
+ }
+ else if (!backend_found) {
+ g_set_error(err, rspamd_stat_quark(), 404, "all learn conditions "
+ "denied learning %s in %s",
+ spam ? "spam" : "ham",
+ classifier ? classifier : "default classifier");
+ }
+ else {
+ g_set_error(err, rspamd_stat_quark(), 404, "cannot find statfile "
+ "backend to learn %s in %s",
+ spam ? "spam" : "ham",
+ classifier ? classifier : "default classifier");
+ }
}
return res;