fsspec/s3fs

When requesting the wrong version of an existing file, the `FileNotFoundError` could be more informative.

kris-lis opened this issue · 3 comments

When one tries to open a file path which exists, but provides a non-existent version_id, the operation throws FileNotFoundError containing the path.

fs.open(path, "rb", version_id=version_id)

It would be very helpful to inform that the version was not found despite the file existing.

"NoSuchVersion": FileNotFoundError,

Perhaps:

"NoSuchVersion": lambda msg, *a, **kw: FileNotFoundError(f"Non-existent version for file {msg}, *a, **kw),

or

class FileVersionNotFoundError(FileNotFoundError):
    pass
...
"NoSuchVersion": FileVersionNotFoundError, 

Thank you for considering!

If the error response from S3 has this information, I agree it would be good to pass it on. A subclass of FileNotFound would indeed be appropriate, I think.

The error response from S3 has this information

I tried

try:
    s3.get_object(Bucket=bucket_name, Key=key, VersionId=version_id)
except ClientError as e:
    print(f"{e}")
    code = e.response['Error']['Code']
    print(f"Found error code {code} when trying to getObject {bucket_name}/{key} {version_id}")

I get the error

An error occurred (NoSuchVersion) when calling the GetObject operation: The specified version does not exist.
Found error code NoSuchVersion when trying to getObject <redacted>/<redacted>  <redacted>

Would you like to include a change to https://github.com/fsspec/s3fs/blob/main/s3fs/errors.py#L115 or nearby that would do this? I think it should either be a subclass of FileNotFound, or just extend the string message with the extra information.