ArchGDAL.jl icon indicating copy to clipboard operation
ArchGDAL.jl copied to clipboard

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

Open felixcremer opened this issue 1 year ago • 2 comments

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.

felixcremer avatar Jun 04 '24 14:06 felixcremer

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

evetion avatar Jun 07 '24 07:06 evetion

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

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

rafaqz avatar Jun 07 '24 08:06 rafaqz