def failed_step()

in src/es_pii_tool/helpers/steps.py [0:0]


def failed_step(task: 'Task', step: 'Step', exc):
    """Function to avoid repetition of code if a step fails"""
    # MissingIndex, BadClientResult are the only ones inbound
    if isinstance(exc, MissingIndex):
        msg = (
            f'Step failed because index {exc.missing} was not found. The upstream '
            f'exception type was MissingIndex, with error message: '
            f'{exc.upstream.args[0]}'
        )
    elif isinstance(exc, BadClientResult):
        msg = (
            f'Step failed because of a bad or unexpected response or result from '
            f'the Elasticsearch cluster. The upstream exception type was '
            f'BadClientResult, with error message: {exc.upstream.args[0]}'
        )
    else:
        msg = f'Step failed for an unexpected reason: {exc}'
    logger.critical(msg)
    step.end(False, errors=True, logmsg=f'{msg}')
    task.end(False, errors=True, logmsg=f'Failed {step.stepname}')
    raise FatalError(msg, exc)