From ab5a5092317c30e152cccf7443537b1a9b44d59a Mon Sep 17 00:00:00 2001
From: gscalamera <graziano.scalamera@elettra.eu>
Date: Fri, 28 Apr 2023 15:35:53 +0200
Subject: [PATCH] Fix wrong exception description and quality

---
 src/AlarmHandler.cpp | 6 +++---
 src/alarm_table.cpp  | 6 +++---
 src/event_table.h    | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/AlarmHandler.cpp b/src/AlarmHandler.cpp
index 94f2af3..d1ac602 100644
--- a/src/AlarmHandler.cpp
+++ b/src/AlarmHandler.cpp
@@ -4454,7 +4454,7 @@ formula_res_t AlarmHandler::eval_formula(tree_parse_info_t tree, string &attr_va
 {
 	formula_res_t res = eval_expression(tree.trees.begin(), attr_values);
 #ifdef _DEBUG_FORMULA
-	DEBUG_STREAM << __func__ << ": 		 finally value=" << res.value << " valid=" << (int)res.valid << " error='" << res.error << "' ex_desc='" << res.ex_desc<<"'" << endl;
+	DEBUG_STREAM << __func__ << ": 		 finally value=" << res.value << " valid=" << (int)res.valid << " error='" << res.error << "' ex_desc='" << res.ex_desc<<"' quality=" << res.quality << endl;
 #endif
 	if(res.valid)
 	{
@@ -4719,7 +4719,7 @@ formula_res_t AlarmHandler::eval_expression(iter_t const& i, string &attr_values
 				res.ex_origin = it->ex_origin;
 				res.error = err.str();
 #ifdef _DEBUG_FORMULA
-				DEBUG_STREAM << "		attribute -> " << string(i->value.begin(), i->value.end()) << " value not valid, desc=" << res.ex_desc << endl;
+				DEBUG_STREAM << "		attribute -> " << string(i->value.begin(), i->value.end()) << " value not valid, desc=" << res.ex_desc << " quality=" << res.quality << endl;
 #endif
 				events->veclock.readerOut();
         		//throw err.str();
@@ -4739,7 +4739,7 @@ formula_res_t AlarmHandler::eval_expression(iter_t const& i, string &attr_values
 				res.ex_origin = it->ex_origin;
 				res.error = err.str();
 #ifdef _DEBUG_FORMULA
-				DEBUG_STREAM << "		attribute -> " << string(i->value.begin(), i->value.end()) << " value empty, desc=" << res.ex_desc << endl;
+				DEBUG_STREAM << "		attribute -> " << string(i->value.begin(), i->value.end()) << " value empty, desc=" << res.ex_desc << " quality=" << res.quality << endl;
 #endif
 				events->veclock.readerOut();
         		//throw err.str();
diff --git a/src/alarm_table.cpp b/src/alarm_table.cpp
index 64f1bad..9ca66f8 100644
--- a/src/alarm_table.cpp
+++ b/src/alarm_table.cpp
@@ -359,6 +359,9 @@ bool alarm_table::update(const string& alm_name, Tango::TimeVal ts, formula_res_
 			status_err_delay = (!res.valid) && (found->second.err_counter >= 1) && ((now.tv_sec - err_delay) > found->second.ts_err_delay.tv_sec);	//error is present and err delay has passed
 		else
 			status_err_delay = (!res.valid);
+		found->second.ex_reason = res.ex_reason;
+		found->second.ex_desc = res.ex_desc;
+		found->second.ex_origin = res.ex_origin;
 		if(!status_err_delay && !res.valid)	//formula result not valid, waiting for err_delay
 		{
 			found->second.attr_values_delay = attr_values;		//save last attr_values to be used in timer_update if this alarm pass over on or off delay
@@ -369,9 +372,6 @@ bool alarm_table::update(const string& alm_name, Tango::TimeVal ts, formula_res_
 			return ret_changed;
 		}
 		found->second.quality = res.quality;
-		found->second.ex_reason = res.ex_reason;
-		found->second.ex_desc = res.ex_desc;
-		found->second.ex_origin = res.ex_origin;
 		bool status_on_delay;
 		if(found->second.on_delay > 0)		//if enabled on delay
 			status_on_delay = ((bool)(res.value != 0)) && (found->second.on_counter >= 1) && ((ts.tv_sec - found->second.on_delay) > found->second.ts_on_delay.tv_sec);	//formula gives true and on delay has passed
diff --git a/src/event_table.h b/src/event_table.h
index d33b7f2..3c5980e 100644
--- a/src/event_table.h
+++ b/src/event_table.h
@@ -58,7 +58,7 @@ class event {
 		string	attname;
 		value_t value;				/* event value */
 		string value_string;	//added for DevString attributes
-		int quality;
+		int quality{Tango::ATTR_INVALID};
 		string ex_reason;
 		string ex_desc;
 		string ex_origin;
-- 
GitLab