Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
BeastyBlacksmith committed Jan 16, 2024
1 parent 94f5d69 commit f95d7d6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/abstract_backend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ backend() = CURRENT_BACKEND.pkg
backends() = _backends

backend_name() = CURRENT_BACKEND.sym
_backend_instance(sym::Symbol)::AbstractBackend =
haskey(_backendType, sym) ? _backendType[sym]() : error("Unsupported backend $sym")
_backend_instance(sym::Symbol)::AbstractBackend = _backendType[sym]()

backend_package_name(sym::Symbol = backend_name()) = _backend_packages[sym]

Expand All @@ -67,10 +66,14 @@ end

backend(sym::Symbol) =
if sym in _backends
backend(_backend_instance(sym))
if initialized(sym)
backend(_backend_instance(sym))
else
@warn "`:$sym` is not initialized, import it first to trigger the extension --- e.g. `import GR; gr()`."
backend()
end
else
@warn "`:$sym` is not initialized, import it first to trigger the extension --- e.g. `import GR; gr()`."
backend()
error("Unsupported backend $sym")
end

function get_backend_module(name::Symbol)
Expand Down

0 comments on commit f95d7d6

Please sign in to comment.