def task(self, args): try: self.login(args) return self.task_impl(args) except Exception as e: tb = traceback.format_exc() raise TaskError(str(e) + '\n' + tb, 'st2.task.base/task_exception')
def task(self, args): self.debug('a debugging statement') self.debug('another debugging statement') raise TaskError( 'a task error', 'mytask/failed', { 'debug': self.debug_statements } )
def exec_cmd(self, cmd, error_msg): result = {} try: stdout = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=self.env) result.update(self.parse_output(stdout)) except subprocess.CalledProcessError as e: tb = traceback.format_exc() raise TaskError(("Could not {}: {} \n {}\n {}".format( error_msg, str(e), e.output, tb)), 'st2.task.base/subprocess_error') except Exception as e: tb = traceback.format_exc() raise TaskError( ("Could not {}: {}\n {}".format(error_msg, str(e), tb)), 'st2.task.base/exec_exception') return result
def task(self, args): raise TaskError('a task error', 'mytask/failed', {'any': 'thing'})