How can I find line number of source code for ERROR?

I am writing Julia code for some small project.
But it seems that Julia script engine (/usr/bin/julia) does not display the line number for error detection.
Althought it shows a line number, it is not the place where the error was detected,
but the place of function which contains error.

Thanks in advance

Does it not go inside the function definition to show the exact line? Please post the relevant error message and explain what exactly is unclear about it.

When I was new to julia, I also seek for tools to help me dubug.
But now I just use println and error to insert to suspicious places to help me locate the error.

Thank you for your replay , ForceBru.
I will make some simple sample for explanation.

Oh, that’s too bad. It is same to me.

Almost all language can show some line number for error place.
Or at least, has something like trace mode like “/bin/bash -x”.
But I can not find them for Julia so far.
I believe it is essential to locate error code.

Hi @psalm1750,
Can you give an example of the code you’re running and for which the error is not precise enough? Please copy-paste the entire code, or at least the entire error message

I usually get loads of line numbers:

julia> using LinearAlgebra

julia> A = [0 1; 0 0]
2Ă—2 Matrix{Int64}:
 0  1
 0  0

julia> inv(A)
ERROR: SingularException(1)
Stacktrace:
 [1] trsm!(side::Char, uplo::Char, transa::Char, diag::Char, alpha::Float64, A::Matrix{Float64}, B::Matrix{Float64})
   @ LinearAlgebra.BLAS ~/.julia/juliaup/julia-1.12.0-rc3+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/blas.jl:2228
 [2] generic_trimatdiv!
   @ ~/.julia/juliaup/julia-1.12.0-rc3+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/triangular.jl:1275 [inlined]
 [3] _ldiv!
   @ ~/.julia/juliaup/julia-1.12.0-rc3+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/triangular.jl:1171 [inlined]
 [4] ldiv!
   @ ~/.julia/juliaup/julia-1.12.0-rc3+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/triangular.jl:1178 [inlined]
 [5] inv(A::UpperTriangular{Int64, Matrix{Int64}})
   @ LinearAlgebra ~/.julia/juliaup/julia-1.12.0-rc3+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/triangular.jl:1228
 [6] inv(A::Matrix{Int64})
   @ LinearAlgebra ~/.julia/juliaup/julia-1.12.0-rc3+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/dense.jl:1083
 [7] top-level scope
   @ REPL[19]:1

Right after the file name, far out to the right, we can see e.g. blas.jl:2228, triangular.jl:1275 [inlined], etc, etc,.
The numbers on the left, [1], [2] can be typed at the julia-prompt followed by ctrl-q to enter an editor on that line in the file. I.e. after the stack trace, to enter the ldiv! function:

julia> 3<push ctrl-q>
...

Do you have an example where you don’t get them?

I don’t get this. It seems that ctrl+q is a VSCode action.
But your instance here is a “nice” instance so that ctrl+click would jump to the file, which is convenient.
There are other instances in which the ctrl+click won’t jump, so that I can only go to github to see the code, but in this case it is way more complicated.

julia> function b()
           println()
           local a = s.i, b = 4.
           println()
       end
b (generic function with 1 method)

julia> function a()
           println()
           b()
           println()
       end
a (generic function with 1 method)

julia> a()
ERROR: BoundsError: attempt to access Float64 at index [2]
Stacktrace:
 [1] indexed_iterate(I::Float64, i::Int64, state::Nothing)
   @ Base ./tuple.jl:168
 [2] b()
   @ Main ./REPL[1]:3
 [3] a()
   @ Main ./REPL[2]:3
 [4] top-level scope
   @ REPL[3]:1

In this case the [2], [3], [4] is not readable, the link in [1] has not hyperlink that I can jump to by clicking.

Ddalle and all other julia menbers, thank you for all of your advice,
And I found that “error line number” is provided in very dark color.
I will check myself and will close my question.

Here, I attached tiny sample file for your reference.
It has an error at line=2.
But it seems to report at line=6.

Thank you for all.

sample.jl (70 Bytes)

It’s in the REPL. I’ve never run VScode.

2 Likes

Oh I see. ctrl+q is better than ctrl + click, the latter cannot open
@ Base .\tuple.jl:168
(I don’t know why). But ctrl + q can indeed goto there.

The stack trace, which you see below the error message, is composed of several numbered “frames”, each corresponding to a distinct line from a distinct function. Indeed functions call each other in sometimes complicated ways, so telling you the innermost location isn’t always sufficient. Here for instance the error originates at line 2 (in your function definition), but it was your function call at line 6 that actually triggered it.
As for the color, you should be able to change the color scheme of your terminal to something more visible?

Hi gdalle, thank you for your quick and appropriate reply, and I agree with you in terms of terminal color.
May be I should set “julia --color=no” option.