Error with goja: goja.valueString is goja.asciiString

Hello,
I have a very strange problem. I’m trying to run postman collection converted to js script, using scenarios. The problem is that I can’t use global variables in two request from one scenario. I mean, in the first request the variable is used in the body without a problem, then when I use it in the second request I get “panic: interface conversion: goja.valueString is goja.asciiString, not goja.unicodeString goroutine 45” following with a big stack trace.

Here is the code snipped where I set the global variables:

    export let options = { 
    	maxRedirects: 4, 
      scenarios: {
    	radostina_user: {
    	  executor: 'constant-vus',
    	  vus: 1,
    	  duration: '2s',
    	  exec: 'radostina_user_test',
    	},
      },
    };
         var i;
    	for (i = 0; i < csvData.length - 2; i = i + 2)
      {
    
	if(i===0){
		pm.globals.set("phoneR", csvData[i]);
		pm.globals.set("otpSeR", csvData[i + 1]);
	}
  }

Here are the requests:

        export function radostina_user_test()  {
   postman[Request]({
    name: "QueryPhone",
    id: "9tshhfghf",
    method: "POST",
    address: "https://test/api/queryPhone",
    data:
      '{\n    "phoneNumber": "{{phoneR}}",\n    "otpSession": "{{**otpSeR**}}"\n}',
    headers: {
      Date: "2020-05-20T15:22:00",
      "Content-Type": "application/json",
      "Accept-Language": "en_EN",
      "Api-version": "v1",
      deviceinfo:
        "eyJhcHBWZXJzaW9uIjoiMC4xLjU4Iiwib3MiOiJpb3MiLCJwdXNoVG9rZW4iOiJkZUpTMl9YQ1JKSTpBUEE5MWJGRE50OXk5b05CQWZvMVZSWXdpNklRUkVMUlhUN3NyZWxVcHR5VVNYWWo4S295ekxSU3RsdndSMERJa3UwdTFNUWVTVm5BX1JsY2t1SDhPTmZsbWxfLWFwWHNtSjVFMXRRRUhubGo5QVU0UHpVY0lNNFQ0LWtGeWJ2LUVNaHBCYU1VSVNSVSIsIm9zVmVyc2lvbiI6IjExLjQuMSIsIm1vZGVsIjoiaVBob25lIDYiLCJ1ZGlkIjoiN0NDRDg4NzMtQzdBMC00QjI4LTkyMjItNjVBRURGNEUxM0M5IiwiaXNSb290ZWQiOmZhbHNlLCJicmFuZE5hbWUiOiJBcHBsZSIsInNjcmVlblJlc29sdXRpb24iOiIzNzUuMC02NjcuMCJ9"
    },

    post(response) {

      var data2 = pm.response.code;
	  var data = pm.response.json();
	  
	  console.log("QueryPhone Radostina " + data2 + " " + JSON.stringify(data));
	  
      pm.globals.set("username", data.username);
      pm.globals.set("userId", data.userId);
	  if (data2 != 200) {
		 console.log("QueryPhone " + data2 );
	  };

    }
  });
    postman[Request]({
        name: "AuthorizUp",
        id: "c8gw454w5y4hh",
        method: "POST",
        address: "https://test/auth/loginUp",
        data:
    		'{"username": "{{username}}" ,"password": "12345","otpSession": "{{**otpSeR**}}"}',
        headers: {
          Date: "2020-05-20T15:22:00",
          "Accept-Language": "en_EN",
          "Content-Type": "application/json",
          deviceInfo:
            "eyJvcyI6ImFuZHJvaWQiLCJvc1ZlcnNpb24iOiI4LjEuMCIsImJyYW5kTmFtZSI6IlhpYW9taSIsIm1vZGVsIjoiUmVkbWkgNiIsInVkaWQiOiJiNTAxYzU4M2MwNDBiOGI2Iiwic2NyZWVuUmVzb2x1dGlvbiI6IjcyMHgxMzQ0LTMyMGRwaS14aGRwaSIsImFwcFZlcnNpb24iOiJ2MC4xLjExMy1pbnRlcm5hbCIsImlzUm9vdGVkIjpmYWxzZX0="
        },		
        post(response) {
          var data = pm.response.json();
    	  var data2 = pm.response.code;
          pm.globals.set("access_token", data.accessToken);
          pm.globals.set("refresh_token", data.refreshToken);
    	  console.log("Login " + data2 + " " + JSON.stringify(data) );
    	  if (data2 != 200) {
    		 console.log("Login " + data2 );
    	  };
        }
      });

It can be seen that I’m using “otpSeR” variable in the two request. I get the error message in the second one. If I hardcode the value of the variable and not using the variable name in the second request, everything is working fine. But when I use the variable I got this strange error message.
I can upload the whole stack trace message if this will help.

I would appreciate it if you could help me.

Best regards

p.s. Sorry I can’t find a way to properly format my code snipped.

Hi @godsent , welcome to the forum!

I have fixed the formatting, you can just wrap them in triple ‘`’ as it supports markdown.

Can you please post the stacktrace and if you can post a full example that can be run (against test.k6.io for example) will be nice, otherwise I will need to cobble the postman imports somehow :sweat_smile:

Thanks for your answer @mstoykov
Here is the full stack trace:

ERRO[0006] panic: interface conversion: goja.valueString is goja.asciiString, not goja.unicodeString
goroutine 89 [running]:s
runtime/debug.Stack(0xc0067e4200, 0xc0067e4220, 0xc0067e41f0)U
        runtime/debug/stack.go:24 +0xa5
github.com/loadimpact/k6/js.(*VU).runFn.func1(0xc007b0e120, 0xc0067e5ca0)
        github.com/loadimpact/k6/js/runner.go:706 +0x1f5
panic(0xfc3f20, 0xc005aa6630)
        runtime/panic.go:969 +0x1c7
github.com/dop251/goja.AssertFunction.func1.1(0xc0067e5ba0)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/runtime.go:2026 +0x95
panic(0xfc3f20, 0xc005aa6630)
        runtime/panic.go:969 +0x1c7
github.com/dop251/goja.(*vm).try.func1(0xc008c16000, 0x0, 0xc0067e5a60, 0x0, 0x0, 0x0, 0xc0067e5ae8)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:406 +0x5d3
panic(0xfc3f20, 0xc005aa6630)
        runtime/panic.go:969 +0x1c7
github.com/dop251/goja.(*vm).try.func1(0xc008c16000, 0x4, 0xc0067e5328, 0x1a, 0x0, 0x0, 0xc0067e53b0)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:406 +0x5d3
panic(0xfc3f20, 0xc005aa6630)
        runtime/panic.go:969 +0x1c7
github.com/dop251/goja.(*valueStringBuilder).WriteSubstring(0xc0067e4dc0, 0x1391020, 0xc0040aae20, 0x1a, 0x40)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/string_unicode.go:258 +0x6ee
github.com/dop251/goja.stringReplace(0x1391020, 0xc0040aae20, 0xc00081d950, 0x2, 0xa, 0x0, 0x0, 0xc0040aae30, 0x1, 0xc005888840)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/builtin_string.go:604 +0x65a
github.com/dop251/goja.(*Runtime).regexpproto_stdReplacer(0xc001eac000, 0x138c640, 0xc005888840, 0xc007bd6340, 0x2, 0x2, 0x138c601, 0xc007bd6340)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/builtin_regexp.go:1195 +0x378
github.com/dop251/goja.(*Runtime).stringproto_replace(0xc001eac000, 0x138caa0, 0xc002764d10, 0xc008c5d090, 0x2, 0x45, 0xc004cda240, 0xbe0000c005aa6600)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/builtin_string.go:661 +0x505
github.com/dop251/goja.(*vm)._nativeCall(0xc008c16000, 0xc0055df2c0, 0x2)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:1817 +0x2c2
github.com/dop251/goja.call.exec(0x2, 0xc008c16000)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:1789 +0xb0b
github.com/dop251/goja.(*vm).run(0xc008c16000)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:307 +0xa2
github.com/dop251/goja.(*vm).try(0xc008c16000, 0xc0067e53b8, 0x0)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:412 +0x16a
github.com/dop251/goja.(*vm).runTry(0xc008c16000, 0x0)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:417 +0x55
github.com/dop251/goja.try.exec(0x5400000000, 0x1, 0xc008c16000)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:2244 +0x58
github.com/dop251/goja.(*vm).run(0xc008c16000)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:307 +0xa2
github.com/dop251/goja.(*funcObject).call(0xc003245e10, 0x138cf00, 0x1d190a0, 0xc0040aa9d0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/func.go:161 +0x33a
github.com/dop251/goja.(*funcObject).Call(...)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/func.go:129
github.com/dop251/goja.(*Runtime).functionproto_apply(0xc001eac000, 0x138c640, 0xc00587b2f0, 0xc008c5ce60, 0x2, 0x68, 0x2a465d, 0x11451c9)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/builtin_function.go:96 +0x149
github.com/dop251/goja.(*vm)._nativeCall(0xc008c16000, 0xc0055c1380, 0x2)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:1817 +0x2c2
github.com/dop251/goja.call.exec(0x2, 0xc008c16000)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:1789 +0xb0b
github.com/dop251/goja.(*vm).run(0xc008c16000)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:307 +0xa2
github.com/dop251/goja.(*funcObject).call(0xc003244410, 0x138cf00, 0x1d190a0, 0xc003f474e0, 0x1, 0x1, 0x0, 0x0, 0xc006731970, 0x29bdea)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/func.go:161 +0x33a
github.com/dop251/goja.(*funcObject).Call(...)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/func.go:129
github.com/dop251/goja.AssertFunction.func1.2()
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/runtime.go:2031 +0x9d
github.com/dop251/goja.(*vm).try(0xc008c16000, 0xc006731b08, 0x0)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/vm.go:412 +0x16a
github.com/dop251/goja.AssertFunction.func1(0x138cf00, 0x1d190a0, 0xc003f474e0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0)
        github.com/dop251/goja@v0.0.0-20210216182323-60bc6ebb9fc1/runtime.go:2030 +0x112
github.com/loadimpact/k6/js.(*VU).runFn(0xc007b0e120, 0x137b4c0, 0xc005a68180, 0x1, 0xc00737f5e0, 0xc003f474e0, 0x1, 0x1, 0x0, 0x0, ...)
        github.com/loadimpact/k6/js/runner.go:711 +0x1be
github.com/loadimpact/k6/js.(*ActiveVU).RunOnce(0xc0074da260, 0x0, 0x0)
        github.com/loadimpact/k6/js/runner.go:659 +0x23b
github.com/loadimpact/k6/lib/executor.getIterationRunner.func1(0x137b480, 0xc0051a6ea0, 0x1363140, 0xc0074da260, 0xc003f47460)
        github.com/loadimpact/k6/lib/executor/helpers.go:86 +0x6d
github.com/loadimpact/k6/lib/executor.ConstantVUs.Run.func3(0x136e1c0, 0xc007b0e120)
        github.com/loadimpact/k6/lib/executor/constant_vus.go:200 +0x17e
created by github.com/loadimpact/k6/lib/executor.ConstantVUs.Run
        github.com/loadimpact/k6/lib/executor/constant_vus.go:211 +0xa19

Goja stack:
file:///C:/Users/imollov/Documents/Mob%20App%20Tests/Journeys_Test/journey_1_prod_Atche.js:419:578(222)
ERRO[0006] a panic occurred in VU code but was caught: interface conversion: goja.valueString is goja.asciiString, not goja.unicodeString  executor=constant-vus scenario=radostina_users

As for the full example I think I can’t do that, because the data is a little sensitive, it’s a banking software. But if I can help with any other information, please let me know?

Best regards,
Ivaylo

This turned out to be a goja issue.

It is unlikely we will get the fix in v0.32.0 which will be released in 2 weeks, hopefully. But this has been the case since k6 v0.28.0, so more than 6 months. But will definitely have a fix for v0.33.0.

I would recommend that you just don’t use the postman way of replacing {{something}} but instead just build the data string entirely before that. You can use template literals if you want instead so it looks more similar to what you have now.

Thank you very much @mstoykov.
I used template literals as you suggested and it works.

Best regards,
Ivaylo