# Debugger not stopping inside open do blocks

**URL:** <https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190>\
**Category:** New to Julia\
**Tags:** debug, vscode\
**Created:** [December 6, 2023, 1:52am UTC](https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190 "2023-12-06T01:52:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![feribg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feribg/32/202948_2.png) [@feribg](https://discourse.julialang.org/u/feribg)\
**Post date:** [December 6, 2023, 1:52am UTC](https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190/1 "2023-12-06T01:52:43Z")

</div>

Using VSCode with latest Julia ext and Julia 1.9.4

Consider the following example:

```julia
    current_files = 0
    n_markets = 0

    open("report.log", "w") do fpReport
        println(fpReport, "CHOOSER log with IS_n=$(is_n) OOS1_n=$(oos1_n) Reps=$(n_reps)")

        open(file_list_names, "r") do file
            for file_path in eachline(file)
                current_files += 1

                if current_files > size(market_dates, 1)
                    market_dates, market_data, current_sizes = resize_market_files!(market_dates, market_data, current_sizes, current_files)
                end
          end
     end
end

```

Stopping on anything outside the `open do` blocks works fine, otherwise any breakpoints inside get ignored by the debugger… this is quite annoying I assume it’s a bug of some sorts ?

This may or may not be related:

> <https://github.com/JuliaDebug/Debugger.jl/issues/234>
>
> When debugging code such as the following:
> 
> \`\`\`julia
> function wrapper() …                                                                                                                                        
> mktempdir() do dir                                                                                                                                          
> open(joinpath(dir, "test.txt"), "w") do io                                                                                                              
> println(io, "data")                                                                                                                                 
> end                                                                                                                                                     
> end                                                                                                                                                         
> end
> \`\`\`
> 
> Using \`n\` to enter a \`do\` block does not work; I think this might be expected, but I wonder if the docs (which state that \`n\` means "step to the next line" should instead say something like "step to the next expression" if that is indeed what it is doing.)
> 
> The truly unexpected piece is when trying to navigate within \`open\` to get into the \`println()\`: after \`si\`'ing and \`so\`'ing my way until I'm in \`open()\`, I am greeted by the following:
> 
> \`\`\`
> 1|debug\> si
> In open(f, args) at io.jl:296
> 295 function open(f::Function, args...; kwargs...)
> \>296 io = open(args...; kwargs...)
> 297 try
> 298 f(io)
> 299 finally
> 300 close(io)
> 
> About to run: (NamedTuple)()
> \`\`\`
> 
> I then hit \`n\` to attempt to jump down to the \`f(io)\`, but when I hit \`n\` I get:
> 
> \`\`\`
> 1|debug\> n
> In open(f, args) at io.jl:296
> 295 function open(f::Function, args...; kwargs...)
> \>296 io = open(args...; kwargs...)
> 297 try
> 298 f(io)
> 299 finally
> 300 close(io)
> 
> About to run: return
> \`\`\`
> 
> I have somehow just skipped to the end of the \`open()\` function, and continuing to step causes me to exit out.

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [December 6, 2023, 6:25am UTC](https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190/2 "2023-12-06T06:25:40Z")

</div>

The vscode debugger compiles all modules except main by default, this makes the debugger faster but also disables the debugger from reaching those parts of the stack.  
[https://www.julia-vscode.org/docs/stable/userguide/debugging/#Settings-to-speed-up-the-debugger](https://www.julia-vscode.org/docs/stable/userguide/debugging/#Settings-to-speed-up-the-debugger)

---

<div class="post-metadata">

**Author:** ![feribg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feribg/32/202948_2.png) [@feribg](https://discourse.julialang.org/u/feribg)\
**Post date:** [December 6, 2023, 6:32am UTC](https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190/3 "2023-12-06T06:32:21Z")

</div>

Well my code is just a random script so its not in a module, it should be falling under Main. But also keep in mind the debugger does work, it just doesnt work within the open do blocks it works before and outside them.

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [December 6, 2023, 6:39am UTC](https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190/4 "2023-12-06T06:39:15Z")

</div>

Yes, my thought was that the open function is not in the Main module, and thus anything run inside it, such as the do block, might not be interpreted. But I’m not sure, and not at the computer right now so can’t test.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [December 6, 2023, 7:48am UTC](https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190/5 "2023-12-06T07:48:16Z")

</div>

Is this `do` block at the top-level? If so, Julia may regard each run of the `do` block as a distinct function. If it were within a function, then Julia would know it is the same function everytime.

```julia-repl
julia> identity() do
       end
#3 (generic function with 1 method)

julia> identity() do
       end
#5 (generic function with 1 method)

julia> identity() do
       end
#7 (generic function with 1 method)

julia> f() = identity() do
       end
f (generic function with 1 method)

julia> f()
#9 (generic function with 1 method)

julia> f()
#9 (generic function with 1 method)

```

---

<div class="post-metadata">

**Author:** ![feribg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feribg/32/202948_2.png) [@feribg](https://discourse.julialang.org/u/feribg)\
**Post date:** [December 6, 2023, 8:10pm UTC](https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190/6 "2023-12-06T20:10:06Z")

</div>

I rewrote mine to actually take a closure and it also didnt work, so does that mean debugger doesn’t work in anonymous functions ☹

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [December 6, 2023, 9:53pm UTC](https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190/7 "2023-12-06T21:53:21Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![feribg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feribg/32/202948_2.png) [@feribg](https://discourse.julialang.org/u/feribg)\
**Post date:** [December 6, 2023, 10:01pm UTC](https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190/8 "2023-12-06T22:01:12Z")

</div>

Above is the repro, i dont know if this is considered a debugger bug or whatever, but im using basic language constructs and a trivial hello world essentially and it doesn’t work without gotchas ☹

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [December 6, 2023, 10:20pm UTC](https://discourse.julialang.org/t/debugger-not-stopping-inside-open-do-blocks/107190/9 "2023-12-06T22:20:49Z")

</div>

I’m pretty sure this is the case as well. To confirm, one can add `"-Base."` to the list of excluded modules per that VS Code docs link and `open` should no longer be excluded.
