diff --git a/js/common/bridge_test.go b/js/common/bridge_test.go index fb685139218..53b9b724e6b 100644 --- a/js/common/bridge_test.go +++ b/js/common/bridge_test.go @@ -348,7 +348,7 @@ func TestBind(t *testing.T) { }}, {"Error", bridgeTestErrorType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.error()`) - assert.Contains(t, err.Error(), "GoError: error") + assert.Contains(t, err.Error(), "error") }}, {"JSValue", bridgeTestJSValueType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { v, err := RunString(rt, `obj.func(1234)`) @@ -358,7 +358,7 @@ func TestBind(t *testing.T) { }}, {"JSValueError", bridgeTestJSValueErrorType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.func()`) - assert.Contains(t, err.Error(), "GoError: missing argument") + assert.Contains(t, err.Error(), "missing argument") t.Run("Valid", func(t *testing.T) { v, err := RunString(rt, `obj.func(1234)`) @@ -369,7 +369,7 @@ func TestBind(t *testing.T) { }}, {"JSValueContext", bridgeTestJSValueContextType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.func()`) - assert.Contains(t, err.Error(), "GoError: func() can only be called from within default()") + assert.Contains(t, err.Error(), "func() can only be called from within default()") t.Run("Context", func(t *testing.T) { *ctxPtr = context.Background() @@ -383,14 +383,14 @@ func TestBind(t *testing.T) { }}, {"JSValueContextError", bridgeTestJSValueContextErrorType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.func()`) - assert.Contains(t, err.Error(), "GoError: func() can only be called from within default()") + assert.Contains(t, err.Error(), "func() can only be called from within default()") t.Run("Context", func(t *testing.T) { *ctxPtr = context.Background() defer func() { *ctxPtr = nil }() _, err := RunString(rt, `obj.func()`) - assert.Contains(t, err.Error(), "GoError: missing argument") + assert.Contains(t, err.Error(), "missing argument") t.Run("Valid", func(t *testing.T) { v, err := RunString(rt, `obj.func(1234)`) @@ -408,7 +408,7 @@ func TestBind(t *testing.T) { }}, {"NativeFunctionError", bridgeTestNativeFunctionErrorType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.func()`) - assert.Contains(t, err.Error(), "GoError: missing argument") + assert.Contains(t, err.Error(), "missing argument") t.Run("Valid", func(t *testing.T) { v, err := RunString(rt, `obj.func(1234)`) @@ -419,7 +419,7 @@ func TestBind(t *testing.T) { }}, {"NativeFunctionContext", bridgeTestNativeFunctionContextType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.func()`) - assert.Contains(t, err.Error(), "GoError: func() can only be called from within default()") + assert.Contains(t, err.Error(), "func() can only be called from within default()") t.Run("Context", func(t *testing.T) { *ctxPtr = context.Background() @@ -433,14 +433,14 @@ func TestBind(t *testing.T) { }}, {"NativeFunctionContextError", bridgeTestNativeFunctionContextErrorType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.func()`) - assert.Contains(t, err.Error(), "GoError: func() can only be called from within default()") + assert.Contains(t, err.Error(), "func() can only be called from within default()") t.Run("Context", func(t *testing.T) { *ctxPtr = context.Background() defer func() { *ctxPtr = nil }() _, err := RunString(rt, `obj.func()`) - assert.Contains(t, err.Error(), "GoError: missing argument") + assert.Contains(t, err.Error(), "missing argument") t.Run("Valid", func(t *testing.T) { v, err := RunString(rt, `obj.func(1234)`) @@ -464,7 +464,7 @@ func TestBind(t *testing.T) { t.Run("Negative", func(t *testing.T) { _, err := RunString(rt, `obj.addWithError(0, -1)`) - assert.Contains(t, err.Error(), "GoError: answer is negative") + assert.Contains(t, err.Error(), "answer is negative") }) }}, {"AddWithError", bridgeTestAddWithErrorType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { @@ -475,12 +475,12 @@ func TestBind(t *testing.T) { t.Run("Negative", func(t *testing.T) { _, err := RunString(rt, `obj.addWithError(0, -1)`) - assert.Contains(t, err.Error(), "GoError: answer is negative") + assert.Contains(t, err.Error(), "answer is negative") }) }}, {"Context", bridgeTestContextType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.context()`) - assert.Contains(t, err.Error(), "GoError: context() can only be called from within default()") + assert.Contains(t, err.Error(), "context() can only be called from within default()") t.Run("Valid", func(t *testing.T) { *ctxPtr = context.Background() @@ -492,7 +492,7 @@ func TestBind(t *testing.T) { }}, {"ContextAdd", bridgeTestContextAddType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.contextAdd(1, 2)`) - assert.Contains(t, err.Error(), "GoError: contextAdd() can only be called from within default()") + assert.Contains(t, err.Error(), "contextAdd() can only be called from within default()") t.Run("Valid", func(t *testing.T) { *ctxPtr = context.Background() @@ -506,7 +506,7 @@ func TestBind(t *testing.T) { }}, {"ContextAddWithError", bridgeTestContextAddWithErrorType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.contextAddWithError(1, 2)`) - assert.Contains(t, err.Error(), "GoError: contextAddWithError() can only be called from within default()") + assert.Contains(t, err.Error(), "contextAddWithError() can only be called from within default()") t.Run("Valid", func(t *testing.T) { *ctxPtr = context.Background() @@ -519,7 +519,7 @@ func TestBind(t *testing.T) { t.Run("Negative", func(t *testing.T) { _, err := RunString(rt, `obj.contextAddWithError(0, -1)`) - assert.Contains(t, err.Error(), "GoError: answer is negative") + assert.Contains(t, err.Error(), "answer is negative") }) }) }}, @@ -529,7 +529,7 @@ func TestBind(t *testing.T) { case bridgeTestContextInjectType: assert.EqualError(t, err, "TypeError: Object has no member 'contextInject' at :1:18(3)") case *bridgeTestContextInjectType: - assert.Contains(t, err.Error(), "GoError: contextInject() can only be called from within default()") + assert.Contains(t, err.Error(), "contextInject() can only be called from within default()") assert.Equal(t, nil, impl.ctx) t.Run("Valid", func(t *testing.T) { @@ -588,7 +588,7 @@ func TestBind(t *testing.T) { }}, {"SumWithContext", bridgeTestSumWithContextType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.sumWithContext(1, 2)`) - assert.Contains(t, err.Error(), "GoError: sumWithContext() can only be called from within default()") + assert.Contains(t, err.Error(), "sumWithContext() can only be called from within default()") t.Run("Valid", func(t *testing.T) { *ctxPtr = context.Background() @@ -626,7 +626,7 @@ func TestBind(t *testing.T) { }}, {"SumWithContextAndError", bridgeTestSumWithContextAndErrorType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { _, err := RunString(rt, `obj.sumWithContextAndError(1, 2)`) - assert.Contains(t, err.Error(), "GoError: sumWithContextAndError() can only be called from within default()") + assert.Contains(t, err.Error(), "sumWithContextAndError() can only be called from within default()") t.Run("Valid", func(t *testing.T) { *ctxPtr = context.Background() diff --git a/js/common/util.go b/js/common/util.go index 98da7d5141f..33320bc7b10 100644 --- a/js/common/util.go +++ b/js/common/util.go @@ -34,5 +34,5 @@ func Throw(rt *goja.Runtime, err error) { if e, ok := err.(*goja.Exception); ok { panic(e) } - panic(rt.NewGoError(err)) + panic(rt.ToValue(err)) } diff --git a/js/common/util_test.go b/js/common/util_test.go index 9e9042c4e1d..72ffa28e3f6 100644 --- a/js/common/util_test.go +++ b/js/common/util_test.go @@ -33,12 +33,12 @@ func TestThrow(t *testing.T) { fn1, ok := goja.AssertFunction(rt.ToValue(func() { Throw(rt, errors.New("aaaa")) })) if assert.True(t, ok, "fn1 is invalid") { _, err := fn1(goja.Undefined()) - assert.EqualError(t, err, "GoError: aaaa") + assert.EqualError(t, err, "aaaa") fn2, ok := goja.AssertFunction(rt.ToValue(func() { Throw(rt, err) })) if assert.True(t, ok, "fn1 is invalid") { _, err := fn2(goja.Undefined()) - assert.EqualError(t, err, "GoError: aaaa") + assert.EqualError(t, err, "aaaa") } } } diff --git a/js/initcontext_test.go b/js/initcontext_test.go index e6357c96bcd..fecf98827b1 100644 --- a/js/initcontext_test.go +++ b/js/initcontext_test.go @@ -52,7 +52,7 @@ func TestInitContextRequire(t *testing.T) { t.Run("Modules", func(t *testing.T) { t.Run("Nonexistent", func(t *testing.T) { _, err := getSimpleBundle(t, "/script.js", `import "k6/NONEXISTENT";`) - assert.Contains(t, err.Error(), "GoError: unknown module: k6/NONEXISTENT") + assert.Contains(t, err.Error(), "unknown module: k6/NONEXISTENT") }) t.Run("k6", func(t *testing.T) { @@ -317,7 +317,7 @@ func TestInitContextOpen(t *testing.T) { t.Run("Nonexistent", func(t *testing.T) { path := filepath.FromSlash("/nonexistent.txt") _, err := getSimpleBundle(t, "/script.js", `open("/nonexistent.txt"); export default function() {}`) - assert.Contains(t, err.Error(), fmt.Sprintf("GoError: open %s: file does not exist", path)) + assert.Contains(t, err.Error(), fmt.Sprintf("open %s: file does not exist", path)) }) t.Run("Directory", func(t *testing.T) { @@ -325,7 +325,7 @@ func TestInitContextOpen(t *testing.T) { fs := afero.NewMemMapFs() assert.NoError(t, fs.MkdirAll(path, 0o755)) _, err := getSimpleBundle(t, "/script.js", `open("/some/dir"); export default function() {}`, fs) - assert.Contains(t, err.Error(), fmt.Sprintf("GoError: open() can't be used with directories, path: %q", path)) + assert.Contains(t, err.Error(), fmt.Sprintf("open() can't be used with directories, path: %q", path)) }) } diff --git a/js/modules/k6/crypto/crypto_test.go b/js/modules/k6/crypto/crypto_test.go index 2b2110ed5db..3ddcecdc9ae 100644 --- a/js/modules/k6/crypto/crypto_test.go +++ b/js/modules/k6/crypto/crypto_test.go @@ -316,7 +316,7 @@ func TestOutputEncoding(t *testing.T) { hasher.update("hello world"); hasher.digest("someInvalidEncoding"); `) - assert.Contains(t, err.Error(), "GoError: Invalid output encoding: someInvalidEncoding") + assert.Contains(t, err.Error(), "Invalid output encoding: someInvalidEncoding") }) } @@ -395,7 +395,7 @@ func TestHMac(t *testing.T) { throw new Error("Hex encoding mismatch: " + resultHex); }`) - assert.Contains(t, err.Error(), "GoError: Invalid algorithm: "+algorithm) + assert.Contains(t, err.Error(), "Invalid algorithm: "+algorithm) }) t.Run(algorithm+" wrapper: invalid", func(t *testing.T) { @@ -405,7 +405,7 @@ func TestHMac(t *testing.T) { throw new Error("Hex encoding mismatch: " + resultHex); }`) - assert.Contains(t, err.Error(), "GoError: Invalid algorithm: "+algorithm) + assert.Contains(t, err.Error(), "Invalid algorithm: "+algorithm) }) } } diff --git a/js/modules/k6/crypto/x509/x509_test.go b/js/modules/k6/crypto/x509/x509_test.go index 96297e1b844..ecaa687956e 100644 --- a/js/modules/k6/crypto/x509/x509_test.go +++ b/js/modules/k6/crypto/x509/x509_test.go @@ -150,7 +150,7 @@ func TestParse(t *testing.T) { _, err := common.RunString(rt, ` x509.parse("bad-certificate");`) assert.Contains( - t, err.Error(), "GoError: failed to decode certificate PEM file") + t, err.Error(), "failed to decode certificate PEM file") }) t.Run("ParseFailure", func(t *testing.T) { @@ -160,7 +160,7 @@ func TestParse(t *testing.T) { if assert.Error(t, err) { assert.Contains(t, err.Error(), - "GoError: failed to parse certificate", + "failed to parse certificate", ) } }) diff --git a/js/modules/k6/http/response_test.go b/js/modules/k6/http/response_test.go index 8668b15bb0d..7fab4c9aec7 100644 --- a/js/modules/k6/http/response_test.go +++ b/js/modules/k6/http/response_test.go @@ -198,13 +198,13 @@ func TestResponse(t *testing.T) { t.Run("Invalid", func(t *testing.T) { _, err := common.RunString(rt, sr(`http.request("GET", "HTTPBIN_URL/html").json();`)) //nolint:lll - assert.Contains(t, err.Error(), "GoError: cannot parse json due to an error at line 1, character 2 , error: invalid character '<' looking for beginning of value") + assert.Contains(t, err.Error(), "cannot parse json due to an error at line 1, character 2 , error: invalid character '<' looking for beginning of value") }) t.Run("Invalid", func(t *testing.T) { _, err := common.RunString(rt, sr(`http.request("GET", "HTTPBIN_URL/invalidjson").json();`)) //nolint:lll - assert.Contains(t, err.Error(), "GoError: cannot parse json due to an error at line 3, character 9 , error: invalid character 'e' in literal true (expecting 'r')") + assert.Contains(t, err.Error(), "cannot parse json due to an error at line 3, character 9 , error: invalid character 'e' in literal true (expecting 'r')") }) }) t.Run("JsonSelector", func(t *testing.T) { @@ -327,7 +327,7 @@ func TestResponse(t *testing.T) { if (res.status != 200) { throw new Error("wrong status: " + res.status); } res.submitForm({ formSelector: "#doesNotExist" }) `)) - assert.Contains(t, err.Error(), sr("GoError: no form found for selector '#doesNotExist' in response 'HTTPBIN_URL/forms/post'")) + assert.Contains(t, err.Error(), sr("no form found for selector '#doesNotExist' in response 'HTTPBIN_URL/forms/post'")) }) t.Run("withGetMethod", func(t *testing.T) { @@ -378,7 +378,7 @@ func TestResponse(t *testing.T) { if (res.status != 200) { throw new Error("wrong status: " + res.status); } res = res.clickLink({ selector: 'a#doesNotExist' }) `)) - assert.Contains(t, err.Error(), sr("GoError: no element found for selector 'a#doesNotExist' in response 'HTTPBIN_URL/links/10/0'")) + assert.Contains(t, err.Error(), sr("no element found for selector 'a#doesNotExist' in response 'HTTPBIN_URL/links/10/0'")) }) t.Run("withRequestParams", func(t *testing.T) { diff --git a/js/modules/k6/k6_test.go b/js/modules/k6/k6_test.go index 9656569f4fd..0b50b2abd30 100644 --- a/js/modules/k6/k6_test.go +++ b/js/modules/k6/k6_test.go @@ -41,7 +41,7 @@ func TestFail(t *testing.T) { rt := goja.New() rt.Set("k6", common.Bind(rt, New(), nil)) _, err := common.RunString(rt, `k6.fail("blah")`) - assert.Contains(t, err.Error(), "GoError: blah") + assert.Contains(t, err.Error(), "blah") } func TestSleep(t *testing.T) { @@ -132,7 +132,7 @@ func TestGroup(t *testing.T) { t.Run("Invalid", func(t *testing.T) { _, err := common.RunString(rt, `k6.group("::", function() { throw new Error("nooo") })`) - assert.Contains(t, err.Error(), "GoError: group and check names may not contain '::'") + assert.Contains(t, err.Error(), "group and check names may not contain '::'") }) } func TestCheck(t *testing.T) { @@ -211,7 +211,7 @@ func TestCheck(t *testing.T) { t.Run("Invalid", func(t *testing.T) { _, err := common.RunString(rt, `k6.check(null, { "::": true })`) - assert.Contains(t, err.Error(), "GoError: group and check names may not contain '::'") + assert.Contains(t, err.Error(), "group and check names may not contain '::'") }) }) diff --git a/js/modules/k6/metrics/metrics_test.go b/js/modules/k6/metrics/metrics_test.go index c3fe9a70d5e..3d8a72c9b0d 100644 --- a/js/modules/k6/metrics/metrics_test.go +++ b/js/modules/k6/metrics/metrics_test.go @@ -90,7 +90,7 @@ func TestMetrics(t *testing.T) { t.Run("ExitInit", func(t *testing.T) { *ctxPtr = lib.WithState(*ctxPtr, state) _, err := common.RunString(rt, fmt.Sprintf(`new metrics.%s("my_metric")`, fn)) - assert.EqualError(t, err, "GoError: metrics must be declared in the init context at apply (native)") + assert.EqualError(t, err, "metrics must be declared in the init context at apply (native)") }) groups := map[string]*lib.Group{