@contextmanager
    def _handle_errors(self, action, on_error_status=IterationResult.FAILED):
        try:
            if action is not None:
                self.logger.debug(action)
            yield
        except (__HOLE__, DeviceNotRespondingError):
            raise
        except (WAError, TimeoutError), we:
            self.device.ping()
            if self.current_job:
                self.current_job.result.status = on_error_status
                self.current_job.result.add_event(str(we))
            try:
                self._take_screenshot('error.png')
            except Exception, e:  # pylint: disable=W0703
                # We're already in error state, so the fact that taking a
                # screenshot failed is not surprising...
                pass
            if action:
                action = action[0].lower() + action[1:]
            self.logger.error('Error while {}:\n\t{}'.format(action, we))
        except Exception, e:  # pylint: disable=W0703
            error_text = '{}("{}")'.format(e.__class__.__name__, e)
            if self.current_job:
                self.current_job.result.status = on_error_status
                self.current_job.result.add_event(error_text)
            self.logger.error('Error while {}'.format(action))
            self.logger.error(error_text)
            if isinstance(e, subprocess.CalledProcessError):
                self.logger.error('Got:')
                self.logger.error(e.output)
            tb = get_traceback()
            self.logger.error(tb)
dataset/ETHPy150Open ARM-software/workload-automation/wlauto/core/execution.py/Runner._handle_errors