# Debugging does not work in vscode for 1 line of code of Zygote

**URL:** https://discourse.julialang.org/t/debugging-does-not-work-in-vscode-for-1-line-of-code-of-zygote/91088
**Category:** Tooling
**Tags:** question
**Created:** [December 1, 2022, 11:26am UTC](https://discourse.julialang.org/t/debugging-does-not-work-in-vscode-for-1-line-of-code-of-zygote/91088 "2022-12-01T11:26:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Joe\_Kuzlovsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joe_kuzlovsky/32/32981_2.png) [@Joe\_Kuzlovsky](https://discourse.julialang.org/u/Joe_Kuzlovsky)
#### Post date: [December 1, 2022, 11:26am UTC](https://discourse.julialang.org/t/debugging-does-not-work-in-vscode-for-1-line-of-code-of-zygote/91088/1 "2022-12-01T11:26:24Z")

</div>

I have this code:

```julia
using Zygote

function test_gradient()
    return gradient(x -> 3x^2 + 2x + 1, 5)    
end

```

and I am trying to debug it by setting a breakpoint in vscode. I get the following error when reaching y, back = pullback(f, args…):

```julia
julia> @run test_gradient()

Error while running the debugger (consider adding a breakpoint for uncaught exceptions):
ERROR: MethodError: no method matching getindex(::Nothing, ::Int64)
Stacktrace:
 [1] stack_trace_request(conn::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, state::VSCodeServer.DebugAdapter.DebuggerState, params::VSCodeServer.DebugAdapter.StackTraceArguments)
   @ VSCodeServer.DebugAdapter ~/.vscode/extensions/julialang.language-julia-1.38.2/scripts/packages/DebugAdapter/src/debugger_requests.jl:403
 [2] (::VSCodeServer.DebugAdapter.var"#128#154"{VSCodeServer.DebugAdapter.DebuggerState})(conn::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, params::VSCodeServer.DebugAdapter.StackTraceArguments)
   @ VSCodeServer.DebugAdapter ~/.vscode/extensions/julialang.language-julia-1.38.2/scripts/packages/DebugAdapter/src/packagedef.jl:55
 [3] dispatch_msg(x::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::VSCodeServer.JSONRPC.MsgDispatcher, msg::Dict{String, Any})
   @ VSCodeServer.JSONRPC ~/.vscode/extensions/julialang.language-julia-1.38.2/scripts/packages/JSONRPC/src/typed.jl:67
 [4] macro expansion
   @ ~/.vscode/extensions/julialang.language-julia-1.38.2/scripts/packages/DebugAdapter/src/packagedef.jl:76 [inlined]
 [5] (::VSCodeServer.DebugAdapter.var"#146#172"{VSCodeServer.var"#186#188", VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, VSCodeServer.JSONRPC.MsgDispatcher})()
   @ VSCodeServer.DebugAdapter ./task.jl:484

```

---

<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 2, 2022, 8:29pm UTC](https://discourse.julialang.org/t/debugging-does-not-work-in-vscode-for-1-line-of-code-of-zygote/91088/2 "2022-12-02T20:29:23Z")

</div>

Zygote does a bunch of finicky things with the compiler that trip up the VS Code debugging. This means, unfortunately, that print debugging is probably the path of least resistance. If you are feeling up for learning the Debugger.jl CLI however (this is what VS Code uses under the hood), I’ve generally found it to be less error prone on Zygote code than the VS Code UI.

---

<div class="post-metadata">

### Author: ![Joe\_Kuzlovsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joe_kuzlovsky/32/32981_2.png) [@Joe\_Kuzlovsky](https://discourse.julialang.org/u/Joe_Kuzlovsky)
#### Post date: [December 5, 2022, 5:14pm UTC](https://discourse.julialang.org/t/debugging-does-not-work-in-vscode-for-1-line-of-code-of-zygote/91088/3 "2022-12-05T17:14:06Z")

</div>

Thanks for confirming, I had this suspicion after looking into the code and understanding more about macros.
