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

AG.read("nonexisting.tif") do r should give hint that file does not exist #428

Open
felixcremer opened this issue Jun 4, 2024 · 2 comments

Comments

@felixcremer
Copy link
Contributor

When I am using AG.read("nonexisting.tif") do r with some ArchGDAL functions I get a confusing GDALError about some Pointer being NULL.
I would have expected an error indicating that the there does not exist a file in that path which happens on a plain AG.read.

julia> AG.read("nonexisting.tif") do r
       AG.nraster(r)
       end
ERROR: GDALError (CE_Failure, code 10):
        Pointer 'hDS' is NULL in 'GDALGetRasterCount'.


Stacktrace:
 [1] maybe_throw
   @ ~/.julia/packages/GDAL/hNyuz/src/error.jl:42 [inlined]
 [2] aftercare
   @ ~/.julia/packages/GDAL/hNyuz/src/error.jl:59 [inlined]
 [3] gdalgetrastercount
   @ ~/.julia/packages/GDAL/hNyuz/src/libgdal.jl:7260 [inlined]
 [4] nraster
   @ ~/.julia/packages/ArchGDAL/xZUPv/src/dataset.jl:662 [inlined]
 [5] #13
   @ ./REPL[33]:2 [inlined]
 [6] read(f::var"#13#14", args::String; kwargs::@Kwargs{})
   @ ArchGDAL ~/.julia/packages/ArchGDAL/xZUPv/src/context.jl:268
 [7] read(f::Function, args::String)
   @ ArchGDAL ~/.julia/packages/ArchGDAL/xZUPv/src/context.jl:265
 [8] top-level scope
   @ REPL[33]:1

I would like to get an error like this also for the do block.

julia> AG.read("nonexisting.tif")
ERROR: GDALError (CE_Failure, code 4):
        nonexisting.tif: No such file or directory

Stacktrace:
 [1] maybe_throw
   @ ~/.julia/packages/GDAL/hNyuz/src/error.jl:42 [inlined]
 [2] aftercare
   @ ~/.julia/packages/GDAL/hNyuz/src/error.jl:59 [inlined]
 [3] gdalopenex(pszFilename::String, nOpenFlags::Int64, papszAllowedDrivers::Ptr{…}, papszOpenOptions::Ptr{…}, papszSiblingFiles::Ptr{…})
   @ GDAL ~/.julia/packages/GDAL/hNyuz/src/libgdal.jl:6635
 [4] #read#79
   @ ~/.julia/packages/ArchGDAL/xZUPv/src/dataset.jl:630 [inlined]
 [5] read(filename::String)
   @ ArchGDAL ~/.julia/packages/ArchGDAL/xZUPv/src/dataset.jl:623
 [6] top-level scope
   @ REPL[34]:1
Some type information was truncated. Use `show(err)` to see complete types.
@evetion
Copy link
Collaborator

evetion commented Jun 7, 2024

Over at GeoArrays, I've used startswith(fn, "/vsi") || occursin(":", fn) || isfile(fn) || error("File not found."), as GDAL can read non-local filepaths.

@rafaqz
Copy link
Collaborator

rafaqz commented Jun 7, 2024

Rasters has something similar, we check all the possible /vsi**

https://github.com/rafaqz/Rasters.jl/blob/main/ext%2FRastersArchGDALExt%2Fgdal_source.jl#L11

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