-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Corrupt linenumber in stacktraces for functions with macros #28618
Comments
What would you see if you did https://docs.julialang.org/en/v0.6.1/manual/stacktraces/#Comparison-with-[backtrace()](@ref)-1 ? |
Not sure if I did this right, but I saw this:
|
Have a look at this denizyuret/Knet.jl#305 (comment) and let's continue tomorrow! |
OK @hpoit But the problem is not the error message itself (I have already corrected). The problem is that Julia v0.7 and v1.0 is telling me that the error is in a wrong line. This is making debugging very difficult. |
Are you using Revise or not? (Revise now corrects line numbers, so it would help to know who is at fault.) |
No, I am not using Revise. Actually this was tested in a fresh environment of Julia. Only the dependencies of MGEO were installed. |
Oh I assumed you were using Revise, in that case, have a look at this too https://youtu.be/l0Go2S_L95M?t=4m53s |
Reading my comment again, I see I was very unclear, so for the sake of both future readers and Julia developers let me try again: I wasn't trying to suggest that Revise could fix this problem for you, I was instead concerned about whether Revise might be causing it. When I said "Revise corrects line numbers," what I really meant is that Revise "tries to correct line numbers in code that you've edited since Julia or the package was built." It can't correct errors that happen by some other mechanism. Of course it's always possible that Revise has a bug, and that in attempting to improve things it actually makes it worse. So now (unfortunately) every time someone reports inaccurate line numbers, the proper procedure is first to ask whether Revise is being used and what happens if the user disables it, e.g., if Revise is being run from the julia --startup-file=no One can test for certain whether Revise is running by typing If the line number mistake only happens when you're using Revise (and it's reproducible when you do), please file it as a Revise bug rather than as a Julia bug. |
Hi @timholy , I understood, but no, I definitely was not using Revise. |
By the way, the error was reproducible using macOS and Linux. |
I wonder what this does Line 787 in 59977eb
and this Lines 781 to 808 in 1fa57f3
|
@hpoit Please do not derail the discussion. This issue is about a specific thing (erroneous line numbers), linking to videos about Revise and random lines of code is not helpful. |
I am trying to see a solution to the problem, Kris. What's causing the incorrect line number, a macro expansion? What's your workflow in this case? Is https://github.com/StephenVavasis/ErrorLineNumber.jl still applicable? |
Aha! I finally found a very minimal working example. The problem is with the macro using StaticArrays
function teste(b)
a = SVector{3, Float64}(0.,0.,0.)
(b < 3) && @error("This is an error!")
a[1] = b
end
teste(3) It gives:
Indicating that the error is in line
which is correct! Notice that the same occurs when using |
By the way, this seems to affect other macros as well. Take a look in this example using Parameter.jl: using Parameters
@with_kw struct Teste{T}
a::T
end
function calcular(i::Teste{T}) where T
@unpack a = T
c = a*b
c
end
calcular(Teste{Float64}(1.0)) It leads to the following error:
The error is in line 10. |
It is also weird that the error is thrown from macro expansion and not from the |
results in wrong linenumber (
on a0de85d (and master for that matter) but results in correct linenumber (
on 2c68f09. |
Bumpity bump, this issue makes it extremely difficult to find bugs in functions just because they happen to have a macro call somewhere. |
In the spirit of the test case added in #27967, let me add this test case that exhibits the issue: using Test
let bt, found = false
@info ""
bt = backtrace()
for frame in map(StackTraces.lookup, bt)
if frame[1].line == @__LINE__() - 2 && frame[1].file == Symbol(@__FILE__)
found = true; break
end
end
@test found
end Interestingly, the issue does not appear when replacing
That may be related or it may be a red herring; just putting it out there. |
FYI, currently testing this patch here:
|
Update: it seems that patch isn't quite correct but was prompted by the correct diagnosis. A similar patch is now pull request #30011. |
Hi guys!
I am seeing a strange problem with both Julia v0.7 and v1.0. Sometimes, when an error occurs, the line indicated by Julia is not the line in which the error happened. Unfortunately, I failed to construct a minimal working example to show the behavior. Hence, I forked my package so that we can reproduce it.
Steps to reproduce
First, add the package in https://github.com/ronisbr/MGEO-test.jl.git
Now, execute the following script:
Julia will output:
However, look what we have at the line 100 of the file
mgeo_real.jl
:The error is more likely in line 138:
Because
vars
is aSVector
.The text was updated successfully, but these errors were encountered: