Unable to serialize request object to protocol buffer: proto: syntax error (line 1:47): unexpected token

I’m receiving the error

ERRO[0002] unable to serialise request object to protocol buffer: proto: syntax error (line 1:47): unexpected token {
        at go.k6.io/k6/js/common.Bind.func1 (native)
        at file:///C:/Users/{myName}/repos/K6-Mach1/exchangeRateGrpc.js:43:130(46)
        at native  executor=constant-vus scenario=default source=stacktrace
  1. I can’t see any syntax errors in the proto file I’m using.
  2. When I switch to a different method, within the same service and proto file, the test runs correctly.
  3. The data I’m passing is valid JSON. I’ve swapped single quotes for double quotes and then for no quotes and back again but I’m still getting a syntax error.
  4. The params I’m passing work with a test of another proto file
import grpc from 'k6/net/grpc';
import { check, sleep } from 'k6';
import { Token } from './bearerToken.js';

const client = new grpc.Client();

client.load(['definitions'], 'Pollos-Hermanos.Contracts.v1.Services.PolloService.proto');

export default ()=> {
    
    const token = Token().access_token;

    const params = {
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${token}`,
        }
      }

      let serverURL = 'pollos.hermanos.io:3459';

    client.connect(serverURL, {
        plaintext: false
    });

const data = {   "ChickenCodes": [ "BAK", "BOK" ], "ExpireDate": {  "seconds": "3638316800"  }}

const response = client.invoke('Pollos-Hermanos.Contracts.v1.Services.PolloService.ChickenService/GetChickenRates', data, params);

check(response, {
    'status is OK': (r) => r && r.status === grpc.StatusOK,
  });

  console.log(JSON.stringify(response.message));

  client.close();
  sleep(500);
};

Hi @jbx !
You have strange symbols look at this screen.
I’ve corrected your code, have a look:

import grpc from 'k6/net/grpc';
import { check, sleep } from 'k6';
import { Token } from './bearerToken.js';

const client = new grpc.Client();

client.load(['definitions'], 'Pollos-Hermanos.Contracts.v1.Services.PolloService.proto');

export default ()=> {

const token = Token().access_token;

const params = {
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`,
    }
  }

  let serverURL = 'pollos.hermanos.io:3459';

client.connect(serverURL, {
    plaintext: false
});
const data = { "ChickenCodes": 
    [ "BAK", "BOK"],
     "ExpireDate": 
     { "seconds": "3638316800" }};

const response = client.invoke('Pollos-Hermanos.Contracts.v1.Services.PolloService.ChickenService/GetChickenRates', data, params);

check(response, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});

console.log(JSON.stringify(response.message));

client.close();
sleep(500);
};

@PaulM may I ask which code editor or integrated development environment you are using (and extensions)? I’m using VS Code but I’m not seeing the same strange symbols you are.

@jbx Yes, I use Visual Studio and followed this recommendation

I commented out a line in the proto message for this service and the error no longer appears.

message ChickenRatesQueryRequest {

   repeated string ChickenCodes = 1;

   // .google.protobuf.Timestamp ExchangeDate = 2;

}
1 Like

My problem is solved by using a data time value in place of “seconds”:

const data = {  

...

  "ExchangeDate": "2022-01-27T15:07:56.572316900Z"

}