Skip to content

Commit c996206

Browse files
committed
Use error hint instead of explicit error
The latter will lead to invalidation when the extension is loaded
1 parent 724107e commit c996206

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/StaticGraphs.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,19 @@ eltype(::Type{StaticEdgeIter{StaticDiGraph{T, U}}}) where T where U = StaticDiGr
114114

115115
include("overrides.jl")
116116

117+
function __init__()
118+
# Register error hint for the `loadsg` and `savesg` functions
119+
if isdefined(Base.Experimental, :register_error_hint)
120+
Base.Experimental.register_error_hint(MethodError) do io, exc, _, _
121+
if exc.f === loadsg
122+
print(io, "\n\nIn order to load static graphs from binary files, you need \
123+
to load the JLD2.jl package.")
124+
elseif exc.f === savesg
125+
print(io,"\n\nIn order to save static graphs to binary files, you need to \
126+
load the JLD2.jl package.")
127+
end
128+
end
129+
end
130+
end
131+
117132
end # module

src/persistence.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,8 @@ abstract type StaticGraphFormat <: AbstractGraphFormat end
77
struct SGFormat <: StaticGraphFormat end
88
struct SDGFormat <: StaticGraphFormat end
99

10-
function loadsg(args...)
11-
error("In order to load static graphs from binary files, you need to load the JLD2.jl \
12-
package")
13-
end
14-
15-
function savesg(args...)
16-
error("In order to save static graphs to binary files, you need to load the JLD2.jl \
17-
package")
18-
end
10+
function loadsg end
11+
function savesg end
1912

2013
loadgraph(fn::AbstractString, gname::String, s::StaticGraphFormat) = loadsg(fn, s)
2114
savegraph(fn::AbstractString, g::AbstractStaticGraph) = savesg(fn, g)

0 commit comments

Comments
 (0)