Browse Source

[Minor] Fix errors reporting on learn errors

tags/1.3.0
Vsevolod Stakhov 7 years ago
parent
commit
0c4806f821
2 changed files with 55 additions and 6 deletions
  1. 8
    1
      src/libserver/task.c
  2. 47
    5
      src/libstat/stat_process.c

+ 8
- 1
src/libserver/task.c View 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;
}
}

+ 47
- 5
src/libstat/stat_process.c View 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;
}


Loading…
Cancel
Save