Skip to content
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

Panic when slicing HTML results #1487

Closed
na-- opened this issue Jun 5, 2020 · 3 comments
Closed

Panic when slicing HTML results #1487

na-- opened this issue Jun 5, 2020 · 3 comments

Comments

@na--
Copy link
Member

na-- commented Jun 5, 2020

Expected Behavior

The following code:

import html from "k6/html";

export default function () {
    var r = html.parseHTML("<html>");
    var o = r.find(".something").slice(0, 4).toArray()
}

will result in a panic like:

panic: runtime error: slice bounds out of range [:4] with capacity 0 [recovered]
	panic: runtime error: slice bounds out of range [:4] with capacity 0 [recovered]
	panic: runtime error: slice bounds out of range [:4] with capacity 0

goroutine 44 [running]:
github.com/loadimpact/k6/vendor/github.com/dop251/goja.AssertFunction.func1.1(0xc003647c48)
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/runtime.go:1489 +0x98
panic(0xe05940, 0xc0012ede60)
	/usr/lib/go/src/runtime/panic.go:969 +0x166
github.com/loadimpact/k6/vendor/github.com/dop251/goja.(*vm).try.func1(0xc0018d11e0, 0x0, 0xc003647b20, 0x0, 0x0, 0x0, 0xc003647b98)
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/vm.go:377 +0x3da
panic(0xe05940, 0xc0012ede60)
	/usr/lib/go/src/runtime/panic.go:969 +0x166
github.com/loadimpact/k6/vendor/github.com/PuerkitoBio/goquery.(*Selection).Slice(...)
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/PuerkitoBio/goquery/array.go:67
github.com/loadimpact/k6/js/modules/k6/html.Selection.Slice(0xc000b66900, 0xc001093f80, 0x0, 0x0, 0x0, 0xc000c67808, 0x1, 0x1, 0xd0f000, 0xc001060270, ...)
	/home/go/src/github.com/loadimpact/k6/js/modules/k6/html/html.go:397 +0x2b9
reflect.callMethod(0xc00181f880, 0xc0036473d8, 0xc0036473c0)
	/usr/lib/go/src/reflect/value.go:710 +0x1ec
reflect.methodValueCall(0x0, 0xc000c67808, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0xc003647630, 0x4d330b, ...)
	/usr/lib/go/src/reflect/asm_amd64.s:35 +0x42
reflect.Value.call(0xd48360, 0xc00181f880, 0x13, 0xe91d6f, 0x4, 0xc0010601e0, 0x2, 0x2, 0xc0036476b0, 0x44b52c, ...)
	/usr/lib/go/src/reflect/value.go:460 +0x8ab
reflect.Value.Call(0xd48360, 0xc00181f880, 0x13, 0xc0010601e0, 0x2, 0x2, 0xc000c67800, 0x82, 0x0)
	/usr/lib/go/src/reflect/value.go:321 +0xb4
github.com/loadimpact/k6/vendor/github.com/dop251/goja.(*Runtime).wrapReflectFunc.func1(0x10d7ac0, 0xc0016a2e00, 0xc0001bbd50, 0x2, 0x7, 0x10d7ac0, 0x10d7ac0)
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/runtime.go:1183 +0x74c
github.com/loadimpact/k6/vendor/github.com/dop251/goja.(*vm)._nativeCall(0xc0018d11e0, 0xc000bbe420, 0x2)
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/vm.go:1757 +0x291
github.com/loadimpact/k6/vendor/github.com/dop251/goja.call.exec(0x2, 0xc0018d11e0)
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/vm.go:1741 +0x4b5
github.com/loadimpact/k6/vendor/github.com/dop251/goja.(*vm).run(0xc0018d11e0)
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/vm.go:289 +0x99
github.com/loadimpact/k6/vendor/github.com/dop251/goja.(*funcObject).Call(0xc000892fc0, 0x10d8100, 0x19ba240, 0xc001619020, 0x1, 0x1, 0x203000, 0x203000)
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/func.go:154 +0x2cc
github.com/loadimpact/k6/vendor/github.com/dop251/goja.AssertFunction.func1.2()
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/runtime.go:1494 +0x96
github.com/loadimpact/k6/vendor/github.com/dop251/goja.(*vm).try(0xc0018d11e0, 0xc002bb8bb0, 0x0)
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/vm.go:383 +0x132
github.com/loadimpact/k6/vendor/github.com/dop251/goja.AssertFunction.func1(0x10d8100, 0x19ba240, 0xc001619020, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0)
	/home/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/runtime.go:1493 +0xfc
github.com/loadimpact/k6/js.(*VU).runFn(0xc0019de880, 0x10cb6a0, 0xc00181f740, 0xc001feea80, 0xc0018d1401, 0x0, 0xc001a72a80, 0xc001619020, 0x1, 0x1, ...)
	/home/go/src/github.com/loadimpact/k6/js/runner.go:532 +0x4e7
github.com/loadimpact/k6/js.(*ActiveVU).RunOnce(0xc0016a23a0, 0x0, 0x0)
	/home/go/src/github.com/loadimpact/k6/js/runner.go:464 +0x23f
github.com/loadimpact/k6/lib/executor.getIterationRunner.func1(0x10cb720, 0xc00362d980, 0x10b8480, 0xc0016a23a0)
	/home/go/src/github.com/loadimpact/k6/lib/executor/helpers.go:86 +0x4d
github.com/loadimpact/k6/lib/executor.PerVUIterations.Run.func3(0x10b84a0, 0xc0019de880)
	/home/go/src/github.com/loadimpact/k6/lib/executor/per_vu_iterations.go:221 +0x18f
created by github.com/loadimpact/k6/lib/executor.PerVUIterations.Run
	/home/go/src/github.com/loadimpact/k6/lib/executor/per_vu_iterations.go:233 +0xb5e

Actual Behavior

k6 should never panic, especially from a script error... Instead, running this code should result in a normal JS exception thrown in the script.

@snitkdan
Copy link

snitkdan commented Nov 4, 2020

hello @na-- ! I just came upon k6 and think this is a really awesome/useful project and would love to see if I can contribute. Would it be alright if I investigate this issue as a possible first contribution?

@na--
Copy link
Member Author

na-- commented Nov 4, 2020

@snitkdan, yes, of course! 🙂 If you have any questions, feel free to ask them here as well.

@na--
Copy link
Member Author

na-- commented Dec 9, 2020

Closed by #1756

@na-- na-- closed this as completed Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants