Skip to content

sourcemap: runtime error: index out of range [-1] #3556

@fullheart

Description

@fullheart

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

  1. Install k6-jslib-aws from Github with npm, to have full TS support:
npm install --save github:grafana/k6-jslib-aws#v0.11.0
  1. Import the attachted k6-jslib-aws-y_ANwLL3.cjs file 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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions