def truncate_exception(e, n=10000):
    """ Truncate exception to be about a certain length """
    if len(str(e)) > n:
        try:
            return type(e)('Long error message', str(e)[:n])
        except Exception:
            return Exception('Long error message', type(e), str(e)[:n])
    else:
        return e
