Skip to content

Commit ec626f2

Browse files
committed
Run callbacks inside try/catch
1 parent b3f081a commit ec626f2

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/CodeTracking.jl

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ function whereis(method::Method)
3333
if lin === nothing
3434
f = method_lookup_callback[]
3535
if f !== nothing
36-
Base.invokelatest(f, method)
36+
try
37+
Base.invokelatest(f, method)
38+
lin = get(method_info, method.sig, nothing)
39+
catch
40+
end
3741
end
38-
lin = get(method_info, method.sig, nothing)
3942
end
4043
if lin === nothing
4144
file, line = String(method.file), method.line
@@ -115,12 +118,15 @@ end
115118
function signatures_at(id::PkgId, relpath::AbstractString, line::Integer)
116119
expressions = expressions_callback[]
117120
expressions === nothing && error("cannot look up methods by line number, try `using Revise` before loading other packages")
118-
for (mod, exsigs) in Base.invokelatest(expressions, id, relpath)
119-
for (ex, sigs) in exsigs
120-
lr = linerange(ex)
121-
lr === nothing && continue
122-
line lr && return sigs
121+
try
122+
for (mod, exsigs) in Base.invokelatest(expressions, id, relpath)
123+
for (ex, sigs) in exsigs
124+
lr = linerange(ex)
125+
lr === nothing && continue
126+
line lr && return sigs
127+
end
123128
end
129+
catch
124130
end
125131
return nothing
126132
end
@@ -167,9 +173,12 @@ function definition(method::Method, ::Type{Expr})
167173
if def === nothing
168174
f = method_lookup_callback[]
169175
if f !== nothing
170-
Base.invokelatest(f, method)
176+
try
177+
Base.invokelatest(f, method)
178+
def = get(method_info, method.sig, nothing)
179+
catch
180+
end
171181
end
172-
def = get(method_info, method.sig, nothing)
173182
end
174183
return def === nothing ? nothing : copy(def[2])
175184
end

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ include("script.jl")
5050
eval(ex)
5151
m = first(methods(replfunc))
5252
@test whereis(m) == ("REPL[1]", 1)
53+
54+
# Test with broken lookup
55+
CodeTracking.method_lookup_callback[] = m -> error("oops")
56+
@test whereis(m) == ("REPL[1]", 1)
5357
end

0 commit comments

Comments
 (0)