Skip to content

Commit ea2141e

Browse files
committed
Use error hint instead of explicit error
The latter will lead to invalidations when JLD2 is loaded
1 parent 9ea2746 commit ea2141e

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/MetaGraphs.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,4 +581,20 @@ include("metadigraph.jl")
581581
include("metagraph.jl")
582582
include("persistence.jl")
583583
include("overrides.jl")
584+
585+
function __init__()
586+
# Register error hint for the `loadmg`, `savemg`, and `savedot` functions
587+
if isdefined(Base.Experimental, :register_error_hint)
588+
Base.Experimental.register_error_hint(MethodError) do io, exc, _, _
589+
if exc.f === loadsg
590+
print(io, "\n\nIn order to load meta graphs from binary files, you need \
591+
to load the JLD2.jl package.")
592+
elseif exc.f === savesg
593+
print(io,"\n\nIn order to save meta graphs to binary files, you need to \
594+
load the JLD2.jl package.")
595+
end
596+
end
597+
end
598+
end
599+
584600
end # module

src/persistence.jl

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,9 @@
33
struct MGFormat <: AbstractGraphFormat end
44
struct DOTFormat <: AbstractGraphFormat end
55

6-
function loadmg(args...)
7-
error("In order to load static graphs from binary files, you need to load the JLD2.jl \
8-
package")
9-
end
10-
11-
function savemg(args...)
12-
error("In order to save static graphs to binary files, you need to load the JLD2.jl \
13-
package")
14-
end
15-
16-
function savedot(args...)
17-
error("In order to save static graphs to binary files, you need to load the JLD2.jl \
18-
package")
19-
end
6+
function loadmg end
7+
function savemg end
8+
function savedot end
209

2110
loadgraph(fn::AbstractString, ::String, ::MGFormat) = loadmg(fn)
2211
savegraph(fn::AbstractString, g::AbstractMetaGraph) = savemg(fn, g)

0 commit comments

Comments
 (0)