Skip to content

Commit

Permalink
stateengine plugin: improve item handling if item does not exist, imp…
Browse files Browse the repository at this point in the history
…rove logging
  • Loading branch information
onkelandy committed Sep 8, 2023
1 parent c940709 commit 840b3c3
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions stateengine/StateEngineAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ def __repr__(self):
return "SeAction Set {}".format(self._name)

def _getitem_fromeval(self):
if self.__item is None:
return
self.__item, self.__value, self.__mindelta, _issue = self.check_getitem_fromeval(self.__item, self.__value,
self.__mindelta)
if self.__item is None:
Expand All @@ -631,13 +633,18 @@ def complete(self, item_state, evals_items=None):
def write_to_logger(self):
SeActionBase.write_to_logger(self)
if isinstance(self.__item, str):
self._log_debug("item from eval: {0}", self.__item)
self._log_increase_indent()
current, _, _, _ = self.check_getitem_fromeval(self.__item)
self._log_debug("Currently eval results in {}", current)
self._log_decrease_indent()
try:
self._log_debug("item from eval: {0}", self.__item)
self._log_increase_indent()
current, _, _, _ = self.check_getitem_fromeval(self.__item)
self._log_debug("Currently eval results in {}", current)
self._log_decrease_indent()
except Exception as ex:
self._log_warning("Issue while getting item from eval {}", ex)
elif self.__item is not None:
self._log_debug("item: {0}", self.__item.property.path)
else:
self._log_debug("item is not defined! Check log file.")
if self.__status is not None:
self._log_debug("status: {0}", self.__status.property.path)
self.__mindelta.write_to_logger()
Expand Down Expand Up @@ -708,7 +715,10 @@ def _execute_set_add_remove(self, state, actionname, namevar, repeat_text, item,

def get(self):
orig_item = self.__item
self._getitem_fromeval()
try:
self._getitem_fromeval()
except Exception as ex:
self._log_warning("Issue while getting item from eval {}", ex)
item_from_eval = orig_item if orig_item != self.__item else False
try:
if self.__item is not None:
Expand Down Expand Up @@ -992,13 +1002,18 @@ def complete(self, item_state, evals_items=None):
def write_to_logger(self):
SeActionBase.write_to_logger(self)
if isinstance(self.__item, str):
self._log_debug("item from eval: {0}", self.__item)
self._log_increase_indent()
current, _, _, _ = self.check_getitem_fromeval(self.__item)
self._log_debug("Currently eval results in {}", current)
self._log_decrease_indent()
try:
self._log_debug("item from eval: {0}", self.__item)
self._log_increase_indent()
current, _, _, _ = self.check_getitem_fromeval(self.__item)
self._log_debug("Currently eval results in {}", current)
self._log_decrease_indent()
except Exception as ex:
self._log_warning("Issue while getting item from eval {}", ex)
elif self.__item is not None:
self._log_debug("item: {0}", self.__item.property.path)
else:
self._log_debug("item is not defined! Check log file.")
if self.__status is not None:
self._log_debug("status: {0}", self.__status.property.path)
self.__mindelta.write_to_logger()
Expand All @@ -1024,6 +1039,8 @@ def _can_execute(self, state):
return True

def _getitem_fromeval(self):
if self.__item is None:
return
self.__item, self.__value, self.__mindelta, _issue = self.check_getitem_fromeval(self.__item, self.__value,
self.__mindelta)
if self.__item is None:
Expand Down Expand Up @@ -1085,7 +1102,10 @@ def real_execute(self, state, actionname: str, namevar: str = "", repeat_text: s

def get(self):
orig_item = self.__item
self._getitem_fromeval()
try:
self._getitem_fromeval()
except Exception as ex:
self._log_warning("Issue while getting item from eval {}", ex)
item_from_eval = orig_item if orig_item != self.__item else False
try:
if self.__item is not None:
Expand Down

0 comments on commit 840b3c3

Please sign in to comment.