`@infiltry` usage

I’m exploring Infiltrator.jl and I am not clear on the use case or purpose of @infiltry. I thought that it would help me debug by catching the state of the code when the exception occurred, but this does not seem to be the case. I thought in this example x would be one of the locals available in the infil> prompt.

julia> using Infiltrator
julia> function foo()

           x = -1
           sqrt(x)
       end
foo (generic function with 1 method)

julia> Main.@infiltry foo()
[ Warning: @infiltry is defined in Infiltrator and is not public in Main
EXCEPTION while infiltrating (on thread 1) top-level frame

infil> @locals
No local variables in this scope.

infil> @exception
ERROR: DomainError with -1.0:
sqrt was called with a negative real argument but will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(f::Symbol, x::Float64)
   @ Base.Math ./math.jl:33
 [2] sqrt
   @ ./math.jl:627 [inlined]
 [3] sqrt(x::Int64)
   @ Base.Math ./math.jl:1546
 [4] foo()
   @ Main ./REPL[7]:4
 [5] top-level scope
   @ REPL[8]:186
 [6] macro expansion
   @ ~/.julia/packages/Infiltrator/W339g/src/Infiltrator.jl:187 [inlined]

What situations is @infiltry useful?

You’re close. @infiltry, similar to @infiltrate belongs in the body of the function you want to infiltrate:

julia> using Infiltrator

julia> function foo(x)
           @infiltry sqrt(x)
       end
foo (generic function with 1 method)

julia> foo(1)
1.0

julia> foo(-1)
EXCEPTION while infiltrating (on thread 1) foo(x::Int64)
  at REPL[2]:2


infil> x
-1

It is a conditional infiltrate point which throws you at the position of the error if it occurs. This can be helpful for example, if you have a function which gets called thousands of times in a loop, but only one specific input causes it to error. You can put @infiltry at the point where the error occurs to get a infiltrator session for the problematic input data.