From 3e36fb9666cf3d8fad73b2f7274f272588303718 Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Thu, 2 Oct 2014 10:11:48 -0700 Subject: [PATCH] Stop stacktracing on InvalidInput exceptions InvalidInput is an expected error case, no need to stacktrace for it, just log the error. Change-Id: Ifcca98effd3ab153af30d21f2f23094210fe8ce3 Closes-Bug: #1376839 --- cinder/flow_utils.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/cinder/flow_utils.py b/cinder/flow_utils.py index d10ef4894..7f1dbac7f 100644 --- a/cinder/flow_utils.py +++ b/cinder/flow_utils.py @@ -18,6 +18,7 @@ from taskflow import states from taskflow import task from taskflow.utils import misc +from cinder import exception from cinder.i18n import _ from cinder.openstack.common import log as logging @@ -85,16 +86,27 @@ class DynamicLogListener(base_listener.ListenerBase): def _task_receiver(self, state, details): # Gets called on task state changes. if 'result' in details and state in base_listener.FINISH_STATES: - # If the task failed, it's useful to show the exception traceback - # and any other available exception information. result = details.get('result') + # If task failed log the exception if isinstance(result, misc.Failure): - self._logger.warn(_("Task '%(task_name)s' (%(task_uuid)s)" - " transitioned into state '%(state)s'") % - {'task_name': details['task_name'], - 'task_uuid': details['task_uuid'], - 'state': state}, - exc_info=tuple(result.exc_info)) + message_dict = {'task_name': details['task_name'], + 'task_uuid': details['task_uuid'], + 'state': state} + if result.check(exception.InvalidInput) is not None: + # Exception is an excepted case, don't stacktrace + message_dict['exception_str'] = result.exception_str + message = (_("Task '%(task_name)s' (%(task_uuid)s)" + " transitioned into state '%(state)s'. " + "Exception: '%(exception_str)s'") % + message_dict) + self._logger.warn(message) + else: + # Task failed with unexpected Exception, show stacktrace + message = (_("Task '%(task_name)s' (%(task_uuid)s)" + " transitioned into state '%(state)s'") % + message_dict) + self._logger.warn(message, + exc_info=tuple(result.exc_info)) else: # Otherwise, depending on the enabled logging level/state we # will show or hide results that the task may have produced -- 2.45.2