示例#1
0
def test_truncate_exception():
    e = ValueError("a" * 1000)
    assert len(str(e)) >= 1000
    f = truncate_exception(e, 100)
    assert type(f) == type(e)
    assert len(str(f)) < 200
    assert "aaaa" in str(f)

    e = ValueError("a")
    assert truncate_exception(e) is e
示例#2
0
def test_truncate_exception():
    e = ValueError('a' * 1000)
    assert len(str(e)) >= 1000
    f = truncate_exception(e, 100)
    assert type(f) == type(e)
    assert len(str(f)) < 200
    assert 'aaaa' in str(f)

    e = ValueError('a')
    assert truncate_exception(e) is e
示例#3
0
def test_truncate_exception():
    e = ValueError('a'*1000)
    assert len(str(e)) >= 1000
    f = truncate_exception(e, 100)
    assert type(f) == type(e)
    assert len(str(f)) < 200
    assert 'aaaa' in str(f)

    e = ValueError('a')
    assert truncate_exception(e) is e
示例#4
0
def error_message(e, status="error"):
    """Produce message to send back given an exception has occurred

    This does the following:

    1.  Gets the traceback
    2.  Truncates the exception and the traceback
    3.  Serializes the exception and traceback or
    4.  If they can't be serialized send string versions
    5.  Format a message and return

    See Also
    --------
    clean_exception : deserialize and unpack message into exception/traceback
    """
    MAX_ERROR_LEN = dask.config.get("distributed.admin.max-error-length")
    tblib.pickling_support.install(e, *collect_causes(e))
    tb = get_traceback()
    tb_text = "".join(traceback.format_tb(tb))
    e = truncate_exception(e, MAX_ERROR_LEN)
    try:
        e_serialized = protocol.pickle.dumps(e)
        protocol.pickle.loads(e_serialized)
    except Exception:
        e_serialized = protocol.pickle.dumps(Exception(repr(e)))
    e_serialized = protocol.to_serialize(e_serialized)

    try:
        tb_serialized = protocol.pickle.dumps(tb)
        protocol.pickle.loads(tb_serialized)
    except Exception:
        tb_serialized = protocol.pickle.dumps(tb_text)

    if len(tb_serialized) > MAX_ERROR_LEN:
        tb_result = None
    else:
        tb_result = protocol.to_serialize(tb_serialized)

    return {
        "status": status,
        "exception": e_serialized,
        "traceback": tb_result,
        "exception_text": repr(e),
        "traceback_text": tb_text,
    }