Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kris-lis opened this issue Jun 21, 2024 · 3 comments

Comments

@kris-lis
Copy link

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!

@martindurant
Copy link
Member

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.

@manish
Copy link

manish commented Aug 11, 2024

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>

@martindurant
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants