]> arthur.barton.de Git - netdata.git/commitdiff
log errors on expressions evaluation, only when the return value is NAN or INFINITY
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 12 Nov 2016 17:40:36 +0000 (19:40 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 12 Nov 2016 17:40:36 +0000 (19:40 +0200)
src/eval.c

index 397b43bd7df1155beff62958cbac5e952b5be894..94c978e3eaaa59639d928907fef6e9b07f622ee1 100644 (file)
@@ -59,20 +59,6 @@ static inline void print_parsed_as_constant(BUFFER *out, calculated_number n);
 // ----------------------------------------------------------------------------
 // evaluation of expressions
 
-static inline calculated_number eval_check_number(calculated_number n, int *error) {
-    if(unlikely(isnan(n))) {
-        *error = EVAL_ERROR_VALUE_IS_NAN;
-        return 0;
-    }
-
-    if(unlikely(isinf(n))) {
-        *error = EVAL_ERROR_VALUE_IS_INFINITE;
-        return 0;
-    }
-
-    return n;
-}
-
 static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABLE *v, int *error) {
     static uint32_t this_hash = 0, now_hash = 0, after_hash = 0, before_hash = 0, status_hash = 0, removed_hash = 0, uninitialized_hash = 0, undefined_hash = 0, clear_hash = 0, warning_hash = 0, critical_hash = 0;
     calculated_number n;
@@ -187,7 +173,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL
     }
 
     *error = EVAL_ERROR_UNKNOWN_VARIABLE;
-    buffer_sprintf(exp->error_msg, "unknown variable '%s'", v->name);
+    buffer_sprintf(exp->error_msg, "[ undefined variable '%s' ] ", v->name);
     return 0;
 }
 
@@ -213,7 +199,6 @@ static inline calculated_number eval_value(EVAL_EXPRESSION *exp, EVAL_VALUE *v,
             break;
     }
 
-    // return eval_check_number(n, error);
     return n;
 }
 
@@ -362,7 +347,6 @@ static inline calculated_number eval_node(EVAL_EXPRESSION *exp, EVAL_NODE *op, i
 
     calculated_number n = operators[op->operator].eval(exp, op, error);
 
-    // return eval_check_number(n, error);
     return n;
 }
 
@@ -1067,8 +1051,19 @@ int expression_evaluate(EVAL_EXPRESSION *exp) {
     buffer_reset(exp->error_msg);
     exp->result = eval_node(exp, (EVAL_NODE *)exp->nodes, &exp->error);
 
-    if(exp->error == EVAL_ERROR_OK)
-        exp->result = eval_check_number(exp->result, &exp->error);
+    if(unlikely(isnan(exp->result))) {
+        if(exp->error == EVAL_ERROR_OK)
+            exp->error = EVAL_ERROR_VALUE_IS_NAN;
+    }
+    else if(unlikely(isinf(exp->result))) {
+        if(exp->error == EVAL_ERROR_OK)
+            exp->error = EVAL_ERROR_VALUE_IS_INFINITE;
+    }
+    else if(unlikely(exp->error == EVAL_ERROR_UNKNOWN_VARIABLE)) {
+        // although there is an unknown variable
+        // the expression was evaluated successfully
+        exp->error = EVAL_ERROR_OK;
+    }
 
     if(exp->error != EVAL_ERROR_OK) {
         exp->result = NAN;