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

Harden detecting file-not-found. #726

Merged
merged 2 commits into from
Dec 13, 2021
Merged

Harden detecting file-not-found. #726

merged 2 commits into from
Dec 13, 2021

Conversation

manthey
Copy link
Member

@manthey manthey commented Dec 13, 2021

This handles some difference in the conda and pip installations of gdal.

Closes #656.

@manthey manthey requested a review from banesullivan December 13, 2021 14:10
return True
if ds.GetDriver().ShortName in {'NITF', 'netCDF'}:
return True
if ds:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the conda installation, GDAL returns a dataset handle even when the file isn't found. In the pip installation, it raises an exception. Both have gdal 3.4.0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is very odd... I wonder what exactly causes this difference? Perhaps a build flag? This would be good to raise in the GDAL conda-forge feedstock

This handles some difference in the conda and pip installations of gdal.
@manthey manthey force-pushed the harden-file-not-found branch from 92fba3c to e9e42c9 Compare December 13, 2021 14:41
Copy link
Contributor

@banesullivan banesullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that this is now raising a TileSourceFileNotFoundError error for my, conda-based, GDAL installation:

>>> import large_image
>>> large_image.open('foo.tif')
Could not find Java JRE compatible with x86_64 architecture
Using python for large_image caching
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bane/Software/kw/large_image/large_image/tilesource/__init__.py", line 143, in open
    return getTileSource(*args, **kwargs)
  File "/Users/bane/Software/kw/large_image/large_image/tilesource/__init__.py", line 131, in getTileSource
    return getTileSourceFromDict(AvailableTileSources, *args, **kwargs)
  File "/Users/bane/Software/kw/large_image/large_image/tilesource/__init__.py", line 118, in getTileSourceFromDict
    raise TileSourceFileNotFoundError(pathOrUri)
large_image.exceptions.TileSourceFileNotFoundError: [Errno 2] foo.tif
>>> large_image.open('/vsicurl?url=https%3A%2F%2Ffoo.com%2Fbar.png&use_head=no&list_dir=no')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bane/Software/kw/large_image/large_image/tilesource/__init__.py", line 143, in open
    return getTileSource(*args, **kwargs)
  File "/Users/bane/Software/kw/large_image/large_image/tilesource/__init__.py", line 131, in getTileSource
    return getTileSourceFromDict(AvailableTileSources, *args, **kwargs)
  File "/Users/bane/Software/kw/large_image/large_image/tilesource/__init__.py", line 118, in getTileSourceFromDict
    raise TileSourceFileNotFoundError(pathOrUri)
large_image.exceptions.TileSourceFileNotFoundError: [Errno 2] /vsicurl?url=https%3A%2F%2Ffoo.com%2Fbar.png&use_head=no&list_dir=no

@manthey manthey merged commit ffe4dbd into master Dec 13, 2021
@manthey manthey deleted the harden-file-not-found branch December 13, 2021 18:36
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

Successfully merging this pull request may close these issues.

Better error type/message for non-existing files
2 participants