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

Add DatasetNotFoundError for consistent error messages #660

Closed
adamjstewart opened this issue Jul 9, 2022 · 0 comments · Fixed by #1714
Closed

Add DatasetNotFoundError for consistent error messages #660

adamjstewart opened this issue Jul 9, 2022 · 0 comments · Fixed by #1714
Assignees
Labels
datasets Geospatial or benchmark datasets documentation Improvements or additions to documentation

Comments

@adamjstewart
Copy link
Collaborator

Summary

We should add a torchgeo.datasets.utils.DatasetNotFoundError class for consistent error messages when datasets aren't found.

Rationale

There is currently very little consistency between the errors reported by different datasets. Some raise RuntimeError, others raise FileNotFoundError. There are dozens of different messages raised by each dataset with little commonality between the text. Some mention using download=True, others mention changing the root directory. Some print the root directory, others leave users guessing.

Implementation

We should subclass FileNotFoundError and except the dataset instance as input. With this, we can check for download and checksum attributes to determine the appropriate message. Some possible formats include:

# Has a `self.download` attribute
f"Dataset not found in `root={self.root}` and `download=False`, either specify a different `root` directory or use `download=True` to automatically download the dataset."

# Doesn't have a `self.download` attribute
f"Dataset not found in `root={self.root}`, either specify a different `root` directory or manually download the dataset."

This will also require consistent documentation in docstrings. Maybe something like:

# Has a ``self.download`` attribute
Raises:                                                                          
    FileNotFoundError: if ``download=False`` but dataset is not found            
        or checksums don't match          

# Doesn't have a ``self.download`` attribute
Raises:                                                                          
    FileNotFoundError: if dataset is not found   

Of course, we'll also need to update the tests as well.

Alternatives

We could simply update everything to have common text, but things would rapidly become out of sync without a centralized class to standardize the error message. This also avoids code duplication.

Additional information

No response

@adamjstewart adamjstewart added documentation Improvements or additions to documentation datasets Geospatial or benchmark datasets labels Jul 9, 2022
@adamjstewart adamjstewart self-assigned this Nov 5, 2023
@adamjstewart adamjstewart added this to the 0.6.0 milestone Nov 5, 2023
@adamjstewart adamjstewart removed this from the 0.6.0 milestone Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasets Geospatial or benchmark datasets documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant