-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
JS script stack traces not referencing the correct lines of code in imported modules #1804
Comments
Thanks for reporting this! I think it's caused by the newline in this module wrapping code https://github.com/loadimpact/k6/blob/c00a85bfea21d748f0f9d11fdbc326087f34c411/js/initcontext.go#L203 I guess we can remove the first |
Duplicate old issue with fewer details, closed in favor of this one, but featuring some sourcemap details: #1107 |
Have a similar issue on Ubuntu. Any pointer on how I could fix this in a custom build? |
@mjkapkan I would recommend to just know that you need to look at the line above for anything that isn't the main module until we fix it ;) |
Oh I guess this could be a different problem then. The referenced lines are off by 100s of lines. Will add an example a bit later. |
@mstoykov here is the example.
Log:
As you can see the test script only has 15 lines, but the lines referenced are way off. This gets even worse with big files. For example the error here is in line 163 on file mainTest.js
So it's a bit hard to trace the error this way. |
In the first one, the error is on line 13 instead of 14 which is what we are mostly talking about in this issue. Can you please open a new one referencing this one but providing the script(or something that reproduces it) where the difference is between 163 and 5xx lines as that is more interesting |
Yes! This amount of lines off is what I was actually dealing with in my real scripts. I made my simple example, it reproduced the issue with a line off, so I called it a day. |
@SaberStrat, well the one line off is easy to explain and fix as @na-- but anything other than that likely has another source which I don't think even #1789 will help with. I would really would like to have an example of what actually gets some bigger difference in the lines numbers so we can better figure out what the problem actually is |
I may try to come up with something. |
Got it! Example:stacktrace_linenumbers.jsimport * as module1 from "./module1.js"
export default function(){
// throw "exception in line 4"
module1.f2()
console.log("in default")
} module1.jsexport function f1(){
throw "exception in line 2"
console.log("in f1")
}
export function f2(){
throw "exception in line 6"
console.log("in f2")
}
export function f3(){
throw "exception in line 10"
console.log("in f3")
}
export function f4(){
throw "exception in line 14"
console.log("in f4")
}
export function f5(){
throw "exception in line 18"
console.log("in f5")
}
export function f6(){
throw "exception in line 22"
console.log("in f6")
}
export function f7(){
throw "exception in line 26"
console.log("in f7")
}
export function f8(){
throw "exception in line 30"
console.log("in f8")
}
export function f9(){
throw "exception in line 34"
console.log("in f9")
}
export function f10(){
throw "exception in line 38"
console.log("in f10")
} Output:
They offset seem to accumulate with the length of the module. |
Thanks @SaberStrat ! I import a lot of modules, so it explains the huge diffs in line numbers I got. |
from my quick look at this, this is mostly due to the large amount of So no quick fixes, sorry. |
can you guys try #2082 and see if that helps you ? |
Pulled the master branch, did a go build on it, and ran that new executable. Alas no change, if I did everything correctly. Still shows line >k6.exe version
k6 v0.33.0 ((devel), go1.16.7, windows/amd64) >k6.exe run C:\Users\me\Documents\loadtesting\tools\k6\bugs\#1804\stacktrace_linenumbers.js
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: C:\Users\me\Documents\loadtesting\tools\k6\bugs\#1804\stacktrace_linenumbers.js
output: -
scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
ERRO[0000] exception in line 6
at f2 (file:///C:/Users/me/Documents/loadtesting/tools/k6/bugs/%231804/module1.js:38:97(2))
at file:///C:/Users/me/Documents/loadtesting/tools/k6/bugs/%231804/stacktrace_linenumbers.js:5:15(4) executor=per-vu-iterations scenario=default source=stacktrace
running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 00m00.0s/10m0s 1/1 iters, 1 per VU
data_received........: 0 B 0 B/s
data_sent............: 0 B 0 B/s
iteration_duration...: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
iterations...........: 1 250.651694/s |
it's not merged (and likely won't be for the next version) so you need to pull |
Oops, right, sorry. Line numbers are correct now! 🤩 Thank you! >k6.exe run C:\Users\me\Documents\loadtesting\tools\k6\bugs\#1804\stacktrace_linenumbers.js
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: C:\Users\me\Documents\loadtesting\tools\k6\bugs\#1804\stacktrace_linenumbers.js
output: -
scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
ERRO[0000] exception in line 6
at f2 (file:///C:/Users/me/Documents/loadtesting/tools/k6/bugs/%231804/module1.js:6:10(2))
at file:///C:/Users/me/Documents/loadtesting/tools/k6/bugs/%231804/stacktrace_linenumbers.js:5:4(4) executor=per-vu-iterations scenario=default source=stacktrace
running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 00m00.0s/10m0s 1/1 iters, 1 per VU
data_received........: 0 B 0 B/s
data_sent............: 0 B 0 B/s
iteration_duration...: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
iterations...........: 1 70.740869/s Column numbers seem to be 0-based, but I assume that's fine? |
I tried to build it with xk6 but it still show incorrect lines. How can I make sure I have built the fixed version? (I am new to go).
|
sorry @mjkapkan I just now see that you wrote 🤦. I think what you did should've correctly created a |
This includes both support for any sourcemap found through the source file and generating sourcemaps when going through babel. There are additional fixes for trying to fix off by 1 line errors in imports, but those may need further work. On not being able to load a sourcemap a warning is emitted but the file is still parsed and compiled just without sourcemaps fixes #1789, #1804
This includes both support for any sourcemap found through the source file and generating sourcemaps when going through babel. There are additional fixes for trying to fix off by 1 line errors in imports, but those may need further work. On not being able to load a sourcemap a warning is emitted but the file is still parsed and compiled just without sourcemaps fixes #1789, #1804
This includes both support for any sourcemap found through the source file and generating sourcemaps when going through babel. There are additional fixes for trying to fix off by 1 line errors in imports, but those may need further work. On not being able to load a sourcemap a warning is emitted but the file is still parsed and compiled just without sourcemaps fixes #1789, #1804
This includes both support for any sourcemap found through the source file and generating sourcemaps when going through babel. There are additional fixes for trying to fix off by 1 line errors in imports, but those may need further work. On not being able to load a sourcemap a warning is emitted but the file is still parsed and compiled just without sourcemaps fixes #1789, #1804
This includes both support for any sourcemap found through the source file and generating sourcemaps when going through babel. There are additional fixes for trying to fix off by 1 line errors in imports, but those may need further work. On not being able to load a sourcemap a warning is emitted but the file is still parsed and compiled just without sourcemaps fixes #1789, #1804
This includes both support for any sourcemap found through the source file and generating sourcemaps when going through babel. There are additional fixes for trying to fix off by 1 line errors in imports, but those may need further work. On not being able to load a sourcemap a warning is emitted but the file is still parsed and compiled just without sourcemaps fixes #1789, #1804
This includes both support for any sourcemap found through the source file and generating sourcemaps when going through babel. There are additional fixes for trying to fix off by 1 line errors in imports, but those may need further work. On not being able to load a sourcemap a warning is emitted but the file is still parsed and compiled just without sourcemaps fixes #1789, #1804
This should get fixed with #2082 and a version with it should be released until the end of the week or the beginning of the next. |
If
k6 run
aborts due to a JS code error/exception in a portion of script code that's imported as a module, the stack trace k6 prints out is not displaying the correct line numbers of the calls leading to the error.If the code error happens in the main script file -- i.e. the one that contains the default export -- the line number is correct.
Environment
k6 version
: k6 v0.29.0 (2020-11-11T13:27:19+0000/d9bced3, go1.15.3, darwin/amd64)Expected Behavior
k6 run
should print the correct line number in the stack, whether the exception happened in the main JS or an imported module.Actual Behavior
k6 run
prints an incorrect line number if the exception happens in an imported module JS. This makes debugging in bigger k6 projects really bothersome, as I have to resort to good old "printf debugging".Steps to Reproduce the Problem
Here's a short simplified example code, consisting of the 'main' file with the default export and two further modules:
stacktrace_linenumbers.js
module1.js
module2.js
Uncommenting the
throw
in the main JS leads to the following printout:The stack trace says
at file:///Users/me/Downloads/k6-v0.29.0-mac/stacktrace_linenumbers.js:4:11(2)
; thethrow
is in line 4. CorrectUncommenting the
throw
in themodule1.js
leads to the following printout:The stack trace says
at f1 (file:///Users/me/Downloads/k6-v0.29.0-mac/module1.js:5:11(2))
; thethrow
is in line 4. Not correctUncommenting the
throw
in themodule2.js
leads to the following printout:The stack trace says
at f2 (file:///Users/me/Downloads/k6-v0.29.0-mac/module2.js:3:11(2))
; thethrow
is in line 2. Not correctAlso, the line in
module1.js
where thef2()
call is in is incorrect too: stack trace saysat f1 (file:///Users/me/Downloads/k6-v0.29.0-mac/module1.js:6:20(4))
;f2()
is in line 5 ofmodule1.js
.The text was updated successfully, but these errors were encountered: