Skip to content

Commit

Permalink
Throw method error or backend exception correctly (#480)
Browse files Browse the repository at this point in the history
* Updated error message when attempting to read a file without the appropriate backend.

The previous error message for reading rasters without an imported backend was confusing. The new message informs callers of the change and suggests the appropriate backend to use.

* Update sources.jl

* Updated error message when attempting to read a file without the appropriate backend.

The previous error message for reading rasters without an imported backend was confusing. The new message informs callers of the change and suggests the appropriate backend to use.

* Updated error message when attempting to read a file without the appropriate backend.

The previous error message for reading rasters without an imported backend was confusing. The new message informs callers of the change and suggests the appropriate backend to use.

The error now reads, "`Rasters.jl` requires backends to be loaded externally as of version 0.8. Run `import $packagename` to read $filename"

* Added warning to docs regarding extensions

* Added warning to docs regarding extensions

* Added warning to docs regarding extensions

* resample and warp now throw MethodError instead of BackendException after loading ArchGDAL

* check extentsion

* remove duplicate method stubs

* include Test

* only test extensions on 1.9

* fix for 1.8

---------

Co-authored-by: JoshuaBillson <[email protected]>
Co-authored-by: JoshuaBillson <[email protected]>
  • Loading branch information
3 people authored Jul 27, 2023
1 parent 0b548f7 commit 2603bd1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/extensions.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
# extensions

# stubs that need ArchGDAL
resample(args...; kw...) = throw(BackendException("ArchGDAL"))
warp(args...; kw...) = throw(BackendException("ArchGDAL"))
function resample(args...; kw...)
@static if isdefined(Base, :get_extension) # julia > 1.9
if isnothing(Base.get_extension(Rasters, :RastersArchGDALExt))
throw(BackendException("ArchGDAL"))
else
throw(MethodError(resample, args))
end
else
throw(BackendException("ArchGDAL"))
end
end
function warp(args...; kw...)
@static if isdefined(Base, :get_extension) # julia > 1.9
if isnothing(Base.get_extension(Rasters, :RastersArchGDALExt))
throw(BackendException("ArchGDAL"))
else
throw(MethodError(warp, args))
end
else
throw(BackendException("ArchGDAL"))
end
end

# Other shared stubs
function layerkeys end
Expand Down
11 changes: 11 additions & 0 deletions test/extensions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Test, Rasters

# These methods should throw a BackendException
@test_throws Rasters.BackendException resample(1, 2, 3)
@test_throws Rasters.BackendException warp(1, 2, 3)

import ArchGDAL

# Should throw a MethodError now that ArchGDAL is loaded
@test_throws MethodError resample(1, 2, 3)
@test_throws MethodError warp(1, 2, 3)
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if VERSION >= v"1.9.0"
Aqua.test_project_extras(Rasters)
Aqua.test_deps_compat(Rasters)
# Aqua.test_project_toml_formatting(Rasters)
@time @safetestset "extensions" begin include("extensions.jl") end
end


Expand Down

0 comments on commit 2603bd1

Please sign in to comment.