k6
k6 copied to clipboard
sourcemap: runtime error: index out of range [-1]
Brief summary
I build with TS some load tests, they are compiled with Vite (Babel and Rollup) in JavaScript. The sourcemap support works fine, except for this file: k6-jslib-aws-y_ANwLL3.cjs.zip (the sourcemap is embedded as the last line of the file)
k6 version
v0.46.0
OS
Docker container with Alpine linux (Host: macOS 14.2.1)
Docker version and image (if applicable)
Custom image with this base images: golang:1.20-alpine + alpine:3.17
Steps to reproduce the problem
- Install
k6-jslib-awsfrom Github with npm, to have full TS support:
npm install --save github:grafana/k6-jslib-aws#v0.11.0
- Import the attachted
k6-jslib-aws-y_ANwLL3.cjsfile and cause an error with empty AWS credentials
import { AWSConfig } from "k6-jslib-aws-y_ANwLL3.cjs";
new AWSConfig({
region: "",
accessKeyId: "",
secretAccessKey: "",
sessionToken: "",
});
Expected behaviour
Show an error with correct sourcemap lookup like this
ERRO[0000] Error: invalid AWS access key ID; reason: size should be between 16 and 128 characters, got 5
at file:///node_modules/k6-jslib-aws/src/internal/config.ts:94:22(57)
at createAwsConfig (file:///src/utils/utils.ts:22:6(34))
at file:///src/writing-fixed-requests-per-minute.ts:11:19(22)
at go.k6.io/k6/js.(*requireImpl).require-fm (native)
at file:///dist/writing-spike-users.cjs:5:27(26) hint="script exception"
Actual behaviour
A thrown JS error cause this Go runtime error:
ERRO[0000] unexpected k6 panic: runtime error: index out of range [-1]
goroutine 1 [running]:
runtime/debug.Stack()
runtime/debug/stack.go:24 +0x65
go.k6.io/k6/cmd.(*rootCommand).execute.func2()
go.k6.io/[email protected]/cmd/root.go:96 +0x69
panic({0x1690780, 0xc0000463d8})
runtime/panic.go:884 +0x213
github.com/go-sourcemap/sourcemap.(*Consumer).source(0xc00096bc40?, 0xc0003a3760, 0x5, 0x19)
github.com/go-sourcemap/[email protected]+incompatible/consumer.go:199 +0x1d8
github.com/go-sourcemap/sourcemap.(*Consumer).Source(0xc0009eb200?, 0xc00096bce0?, 0xc00004ebd0?)
github.com/go-sourcemap/[email protected]+incompatible/consumer.go:178 +0x6d
github.com/dop251/goja/file.(*File).Position(0xc000132600, 0xd2)
github.com/dop251/[email protected]/file/file.go:161 +0x1c5
github.com/dop251/goja.(*StackFrame).Position(0xc00096bdb0)
github.com/dop251/[email protected]/runtime.go:228 +0x4b
github.com/dop251/goja.(*StackFrame).Write(0xc00096bdb0, 0x176830c?)
github.com/dop251/[email protected]/runtime.go:271 +0x76
github.com/dop251/goja.(*Exception).writeFullStack(0xc00096bdf8?, 0xc00010e4e0?)
github.com/dop251/[email protected]/runtime.go:363 +0x7e
github.com/dop251/goja.(*Exception).String(0xc0009f1530?)
github.com/dop251/[email protected]/runtime.go:384 +0x85
go.k6.io/k6/js.(*scriptException).StackTrace(0x1ac7b00?)
go.k6.io/[email protected]/js/runner.go:915 +0x1c
go.k6.io/k6/cmd.(*rootCommand).execute(0xc0004f7d40)
go.k6.io/[email protected]/cmd/root.go:118 +0x1f5
go.k6.io/k6/cmd.Execute()
go.k6.io/[email protected]/cmd/root.go:137 +0x31
main.main()
k6/main.go:12 +0x17
Interestingly, the runtime error only occurs when I repeat the execution in quick sequence only in the first execution. The other executions show the correct JS error.
By the way: Why this go build does not install the latest version (0.46 instead 0.48)?
go install go.k6.io/xk6/cmd/xk6@latest
xk6 build \
--with github.com/grafana/xk6-dashboard \
--output /tmp/k6
Hey @fullheart, thanks for opening this issue.
k6-jslib-aws-y_ANwLL3.cjs.zip
Can you post it via a gist, in a dedicated repository, or just do a collapsable code block in the issue's description, please? In this way, we don't have to download a file that we can't review before, thanks.
By the way: Why this go build does not install the latest version (0.46 instead 0.48)?
Regarding it, I've opened a pull request for fixing it https://github.com/grafana/xk6-dashboard/pull/146.
Hey @codebien Thank you for fixing the outdated version in xk6-dashboard. I created a repo with code to reproduce this error: https://github.com/fullheart/k6-issue-3556 It is interesting that the error only occurs in this file constellation (if you some code files, the problem is suddenly solved) Thank you for your help!
Hey, @fullheart the repository doesn't seem to be available. Maybe, did you forget to mark it public?
@codebien Sorry, now the repo is public 😄
if you delete the code file, the problem is suddenly solved
Can you clarify, please? What code file?
Note that it would help me if we could rid of everything not required for triggering the panic (if we may remove typescript, docker, etc..) as it will speed up my troubleshooting process.
Hey @codebien I have already removed a lot of code to simplify the test case for you. If I remove too many files, the bug can no longer be reproduced (the bug only appears in this code constellation). And without Typescript, we lose the source map, so the bug could not be reproduced either. The only thing I can do is removing docker. But as it is a possible workflow, I thought running it in docker should not be a problem. What do you think? Thanks.
What do you think? Thanks.
It is fine, thanks.
Hey @fullheart, quick update, as you can see from the linked issue, we identified the root of the problem. We're going to work in the next few days to apply a fix for k6.