Esempio n. 1
0
File: _s3fs.py Progetto: miarec/s3fs
def s3errors(path):
    """Translate S3 errors to FSErrors."""
    try:
        yield
    except ClientError as error:
        _error = error.response.get('Error', {})
        error_code = _error.get('Code', None)
        response_meta = error.response.get('ResponseMetadata', {})
        http_status = response_meta.get('HTTPStatusCode', 200)
        error_msg = _error.get('Message', None)
        if error_code == 'NoSuchBucket':
            raise errors.ResourceError(path, exc=error, msg=error_msg)
        if http_status == 404:
            raise errors.ResourceNotFound(path)
        elif http_status == 403:
            raise errors.PermissionDenied(path=path, msg=error_msg)
        else:
            raise errors.OperationFailed(path=path, exc=error)
    except SSLError as error:
        raise errors.OperationFailed(path, exc=error)
    except EndpointConnectionError as error:
        raise errors.RemoteConnectionError(
            path,
            exc=error,
            msg="{}".format(error)
        )
Esempio n. 2
0
def dlkerrors(path):
    """ Translate Datalake errors to FSErrors.

        FS errors: https://docs.pyfilesystem.org/en/latest/reference/errors.html
        DLK errors: https://docs.pyfilesystem.org/en/latest/reference/errors.html
    """
    try:
        yield
    except client_error.FileNotFoundError as error:
        raise errors.ResourceNotFound(path, exc=error)
    except client_error.FileExistsError as error:
        raise errors.FileExists(path, exc=error)
    except client_error.PermissionError as error:
        raise errors.PermissionDenied(path, exc=error)
    except client_error.DatalakeBadOffsetException as error:
        raise errors.RemoteConnectionError(path,
                                           exc=error,
                                           msg="DatalakeBadOffsetException")
    except client_error.DatalakeIncompleteTransferException as error:
        raise errors.RemoteConnectionError(
            path, exc=error, msg="DatalakeIncompleteTransferException")
    except client_error.DatalakeRESTException as error:
        raise errors.RemoteConnectionError(path,
                                           exc=error,
                                           msg="DatalakeRESTException")