Exemplo n.º 1
0
def handle_errors():
    try:
        yield
    except Exception as exc:
        logger.debug("Exception details:", exc_info=exc)
        messages = [str(e) for e in utils.causes(exc)]
        raise click.ClickException("\n".join(e for e in messages if e))
Exemplo n.º 2
0
def handle_errors():
    try:
        yield
    except exceptions.ProcrastinateException as exc:
        logger.debug("Exception details:", exc_info=exc)
        messages = [str(e) for e in utils.causes(exc)]
        raise click.ClickException("\n".join(e for e in messages if e))
    except NotImplementedError:
        raise click.UsageError(
            "Missing app. This most probably happened because procrastinate needs an "
            "app via --app or the PROCRASTINATE_APP environment variable")
Exemplo n.º 3
0
def test_causes():
    e1, e2, e3 = AttributeError("foo"), KeyError("bar"), IndexError("baz")

    try:
        try:
            # e3 will be e2's __cause__
            raise e2 from e3
        except Exception:
            # e2 will be e1's __context__
            raise e1
    except Exception as exc2:
        result = list(utils.causes(exc2))

    assert result == [e1, e2, e3]