Is there a way to suppress the stacktrace that accompanies an error in the Julia REPL?
Asked Answered
R

2

10

Is there a way to suppress the stacktrace that accompanies an error in the Julia REPL (VS Code specific methods acceptable)? It fills my screen with a lot of output that is not useful for me to fix the error, and I regularly must scroll up through it to find the useful, single, first line of error description, and find this inefficient and messy.

Rachael answered 2/5, 2020 at 0:41 Comment(1)
I agree, library/3rd party code should not be traced. After proper debugging tools (currently extremely slow), this is for me one of the most important issues to fixRedan
S
1

Maybe not quite what you wanted, but it's close:

julia> # Sequence of dummy functions to generate long stack trace
       f() = g()
       g() = h()
       h() = k()
       k() = error("Hello world")
k (generic function with 2 methods)

julia> # Default: long stacktrace
       f()
ERROR: Hello world
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] k() at ./REPL[72]:5
 [3] h() at ./REPL[72]:4
 [4] g() at ./REPL[72]:3
 [5] f() at ./REPL[72]:2
 [6] top-level scope at REPL[73]:2

julia> # try/catch to eliminate stacktrace
       try
           f()
       catch e
           printstyled(stderr,"ERROR: ", bold=true, color=:red)
           printstyled(stderr,sprint(showerror,e), color=:light_red)
           println(stderr)
       end
ERROR: Hello world
Smectic answered 5/5, 2020 at 3:56 Comment(0)
H
0

VS Code specific solution

Installing the "Julia Insiders" extension instead of the regular "Julia" extension solves this issue, as explained here.

I can see the fix is merged into the main branch but for some reason it hasn't made its way into the regular extension.

Hamate answered 7/7, 2022 at 22:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.