Skip to content

json: method descriptors don't have "type" field #528

@paralin

Description

@paralin

Getting this error:

/home/paralin/Documents/fusecloud-ng/grpc-bus/node_modules/protobufjs/src/util.js:66
    return TypeError(name + " must be " + (description || "a string"));
           ^
TypeError: type (is undefined) [undefined] must be a string
    at TypeError (native)
    at util._TypeError (/home/paralin/Documents/fusecloud-ng/grpc-bus/node_modules/protobufjs/src/util.js:66:12)
    at new Method (/home/paralin/Documents/fusecloud-ng/grpc-bus/node_modules/protobufjs/src/method.js:36:15)
    at Function.fromJSON (/home/paralin/Documents/fusecloud-ng/grpc-bus/node_modules/protobufjs/src/method.js:105:12)
    at /home/paralin/Documents/fusecloud-ng/grpc-bus/node_modules/protobufjs/src/service.js:80:32
    at Array.forEach (native)
    at Function.fromJSON (/home/paralin/Documents/fusecloud-ng/grpc-bus/node_modules/protobufjs/src/service.js:79:35)
    at /home/paralin/Documents/fusecloud-ng/grpc-bus/node_modules/protobufjs/src/namespace.js:131:50
    at Array.forEach (native)
    at Namespace.addJSON (/home/paralin/Documents/fusecloud-ng/grpc-bus/node_modules/protobufjs/src/namespace.js:127:33)

Proto:

In "compiled" inline JS object:

/* tslint:disable:trailing-comma */
/* tslint:disable:quotemark */
/* tslint:disable:max-line-length */
export const PROTO_DEFINITIONS = {
  "nested": {
    "mock": {
      "nested": {
        "Greeter": {
          "methods": {
            "SayHello": {
              "requestType": "HelloRequest",
              "responseType": "HelloReply"
            },
            "SayHelloClientStream": {
              "requestType": "HelloRequest",
              "requestStream": true,
              "responseType": "HelloReply"
            },
            "SayHelloServerStream": {
              "requestType": "HelloRequest",
              "responseType": "HelloReply",
              "responseStream": true
            },
            "SayHelloBidiStream": {
              "requestType": "HelloRequest",
              "requestStream": true,
              "responseType": "HelloReply",
              "responseStream": true
            }
          }
        },
        "EDummyEnum": {
          "values": {
            "DUMMY": 0
          }
        },
        "HelloRequest": {
          "fields": {
            "name": {
              "type": "string",
              "id": 1
            }
          }
        },
        "HelloReply": {
          "fields": {
            "message": {
              "type": "string",
              "id": 1
            }
          }
        }
      }
    }
  }
};

When I try to load it with fromJSON I get the error above. The error output has a bit of extra output I put in when debugging the issue. The "type" argument is undefined, probably because the methods do not have a "type" field on them from the pbjs output.

Fix: either put "rpc" in the type field in the pbjs output, or default "undefined" -> "rpc".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions