From ec626f2584d63ba46eb4fee082233d7b92095885 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 15 Mar 2019 04:27:50 -0500 Subject: [PATCH] Run callbacks inside try/catch --- src/CodeTracking.jl | 27 ++++++++++++++++++--------- test/runtests.jl | 4 ++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/CodeTracking.jl b/src/CodeTracking.jl index a21fc46..8b76555 100644 --- a/src/CodeTracking.jl +++ b/src/CodeTracking.jl @@ -33,9 +33,12 @@ function whereis(method::Method) if lin === nothing f = method_lookup_callback[] if f !== nothing - Base.invokelatest(f, method) + try + Base.invokelatest(f, method) + lin = get(method_info, method.sig, nothing) + catch + end end - lin = get(method_info, method.sig, nothing) end if lin === nothing file, line = String(method.file), method.line @@ -115,12 +118,15 @@ end function signatures_at(id::PkgId, relpath::AbstractString, line::Integer) expressions = expressions_callback[] expressions === nothing && error("cannot look up methods by line number, try `using Revise` before loading other packages") - for (mod, exsigs) in Base.invokelatest(expressions, id, relpath) - for (ex, sigs) in exsigs - lr = linerange(ex) - lr === nothing && continue - line ∈ lr && return sigs + try + for (mod, exsigs) in Base.invokelatest(expressions, id, relpath) + for (ex, sigs) in exsigs + lr = linerange(ex) + lr === nothing && continue + line ∈ lr && return sigs + end end + catch end return nothing end @@ -167,9 +173,12 @@ function definition(method::Method, ::Type{Expr}) if def === nothing f = method_lookup_callback[] if f !== nothing - Base.invokelatest(f, method) + try + Base.invokelatest(f, method) + def = get(method_info, method.sig, nothing) + catch + end end - def = get(method_info, method.sig, nothing) end return def === nothing ? nothing : copy(def[2]) end diff --git a/test/runtests.jl b/test/runtests.jl index 0badd71..6c575c3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -50,4 +50,8 @@ include("script.jl") eval(ex) m = first(methods(replfunc)) @test whereis(m) == ("REPL[1]", 1) + + # Test with broken lookup + CodeTracking.method_lookup_callback[] = m -> error("oops") + @test whereis(m) == ("REPL[1]", 1) end