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

TypeError when attempting to getPackageObject from descriptor #1

Open
DLesage25 opened this issue Dec 21, 2022 · 15 comments
Open

TypeError when attempting to getPackageObject from descriptor #1

DLesage25 opened this issue Dec 21, 2022 · 15 comments

Comments

@DLesage25
Copy link

I'm getting the following TypeError when attempting to follow the readme to get the package object from a descriptor:

node_modules/protobufjs/ext/descriptor/index.js:219
                type.oneofsArray[descriptor.field[i].oneofIndex].add(field);
                                                                 ^
TypeError: Cannot read properties of undefined (reading 'add')

I am able to get the descriptor fine, I've logged it and the values in it make sense. My code:

    const c = new GrpcReflection(
        opts.API_URL,
        grpc.credentials.createInsecure()
    );

    // Find protobufjs descriptor by symbol in grpc reflection server
    const descriptor = await c.getDescriptorBySymbol('models.EventService');

    // Get @grpc/grpc-js package object
    const packageObject = descriptor.getPackageObject({
        keepCase: true,
        enums: String,
        longs: String,
    });
@gawsoftpl
Copy link
Owner

Please send your protobufjs version

@marcustut
Copy link

marcustut commented Feb 1, 2023

I'm also having this issue and I'm on protobufjs 7.2.0. The following is my logs

/Users/marcus/balaena-quant/rbs/node_modules/.pnpm/[email protected]/node_modules/protobufjs/ext/descriptor/index.js:219
                type.oneofsArray[descriptor.field[i].oneofIndex].add(field);
                                                                 ^


TypeError: Cannot read properties of undefined (reading 'add')
    at Function.fromDescriptor (/Users/marcus/balaena-quant/rbs/node_modules/.pnpm/[email protected]/node_modules/protobufjs/ext/descriptor/index.js:219:66)
    at Function.fromDescriptor (/Users/marcus/balaena-quant/rbs/node_modules/.pnpm/[email protected]/node_modules/protobufjs/ext/descriptor/index.js:92:42)
    at createPackageDefinitionFromDescriptorSet (/Users/marcus/balaena-quant/rbs/node_modules/.pnpm/@[email protected]/node_modules/@grpc/proto-loader/build/src/index.js:160:32)
    at Object.loadFileDescriptorSetFromObject (/Users/marcus/balaena-quant/rbs/node_modules/.pnpm/@[email protected]/node_modules/@grpc/proto-loader/build/src/index.js:215:12)
    at Descriptor.getPackageDefinition (/Users/marcus/balaena-quant/rbs/node_modules/.pnpm/[email protected]/node_modules/grpc-js-reflection-client/dist/src/Descriptor.js:21:28)
    at Descriptor.getPackageObject (/Users/marcus/balaena-quant/rbs/node_modules/.pnpm/[email protected]/node_modules/grpc-js-reflection-client/dist/src/Descriptor.js:24:48)
    at grpcPlugin (/Users/marcus/balaena-quant/rbs/src/plugins/grpc.ts:15:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

@gawsoftpl
Copy link
Owner

gawsoftpl commented Feb 1, 2023

I add this issue to my list. I will try to fix it and push a new release in next week.

@pgerstoft
Copy link

@gawsoftpl any updates? I ran into this issue as well.

@MichaelKheel
Copy link

how to fix ?

@gawsoftpl
Copy link
Owner

I am working on new version of grpc reflection client. I need couple days for fix this.

@gawsoftpl
Copy link
Owner

gawsoftpl commented May 10, 2023

I published new version of this package.

If you have still above error please try new version of protobufjs
"protobufjs": "^7.2.3"

@alizhan-plb
Copy link

@gawsoftpl is this problem solved? I still have error Cannot read properties of undefined (reading 'add')

@gawsoftpl
Copy link
Owner

@alizhan-plb Please send your dependencies list from package.json and proto file.
I updated dependencies packages in https://github.com/gawsoftpl/grpc-js-reflection-api-client. Sometimes it happens that @grpc/grpc-js must be updated to the latest version

@gawsoftpl gawsoftpl reopened this Dec 19, 2024
@alizhan-plb
Copy link

@gawsoftpl
package.json

 "@grpc/grpc-js": "^1.12.4",
 "google-protobuf": "^3.21.4",
 "grpc-js-reflection-client": "^1.2.22",
 "protobufjs": "^7.4.0",

proto

syntax = "proto3";

package ***.***.***.***.grpc;

import "google/api/annotations.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/***/***/pkg/model/application/v3";

option java_package = "com.***.***.***.***.model.application.v3";
option java_outer_classname = "ServiceApplication_";
option java_multiple_files = true;


service ServiceApplication {

    rpc Apply (Application) returns (Application) {
        option (google.api.http) = {
            post: "/***/***/***/***/***/api/application"
            body: "*"
        };
    }

    rpc Inspect (InspectState) returns (InspectState) {
        option (google.api.http) = {
            post: "/***/***/***/***/***/api/inspect"
            body: "*"
        };
    }

}

message Application {
    message Metadata {
        string namespace = 1;
        string name      = 2;
        string uid       = 3;
    }

    message Spec {
        ApplicationSpecAction      action = 1;
        .google.protobuf.Struct    configuration = 2;
    }

    message Status {
        ApplicationStatusState state = 1;
    }

    Metadata metadata = 1;
    Spec     spec     = 2;
    Status   status   = 3;
}

enum ApplicationSpecAction {
    ApplicationSpecAction__UNKNOWN = 0;

    ApplicationSpecAction__START   = 1;
    ApplicationSpecAction__STOP    = 2;

    ApplicationSpecAction__START__JOB = 3;
    ApplicationSpecAction__STOP__JOB = 4;
}

enum ApplicationStatusState {
    ApplicationStatusState__UNKNOWN    = 0;

    ApplicationStatusState__STARTING   = 1;
    ApplicationStatusState__STARTED    = 2;
    ApplicationStatusState__RUNNING    = 3;
    ApplicationStatusState__FAILED     = 4;
    ApplicationStatusState__STOPPING   = 5;
    ApplicationStatusState__STOPPED    = 6;
}

message InspectState {
    message Metadata {
        string namespace = 1;
        string name      = 2;
        string uid       = 3;
    }

    message Spec {
        InspectStateEventType event_type = 1;

        optional __Event__data = 101;
    }

    Metadata metadata = 1;
    Spec     spec     = 2;
}

enum InspectStateEventType {
    InspectStateEventType__UNKNOWN = 0;
    
    InspectStateEventType__JOB = 1;
}

@gawsoftpl
Copy link
Owner

gawsoftpl commented Dec 20, 2024

service ServiceApplication {

rpc Apply (Application) returns (Application) {
    option (google.api.http) = {
        post: "/***/***/***/***/***/api/application"
        body: "*"
    };
}

rpc Inspect (InspectState) returns (InspectState) {
    option (google.api.http) = {
        post: "/***/***/***/***/***/api/inspect"
        body: "*"
    };
}

}

I see that you use rest map for grpc, do you use gRPC-Gateway?
When you want to download proto file via reflection of grpc you connect direct to grpc server?

Please try upgrade "grpc-js-reflection-client" to version 1.2.23

@tamama-plb
Copy link

tamama-plb commented Dec 23, 2024

I see that you use rest map for grpc, do you use gRPC-Gateway?

  • Yes, we use gRPC-Gateway for gRPC <> (streaming-)REST proxy.
  • We also use WSProxy for gRPC <> websocket proxy
  • (The option arguments (google.app.http) originates from googleapis github repository.

When you want to download proto file via reflection of grpc you connect direct to grpc server?

  • Yes, that's a direct connect to grpc-server. (Here, reflection has nothing to do with the above proxies)
  • To be precise, this is under --insecure or --plaintext (since they are purely internal)
  • For your curiousity, the same gRPC (+reflection) service works OK with grpc-ui and grpcurl (Proving that the grpc-reflection server is legit)
  • Further proof for the validity of our reflection service is further confirmed via python grpc_requests client library.

Please try upgrade "grpc-js-reflection-client" to version 1.2.23

@alizhan-plb ^ FYI

Thanks.

@alizhan-plb
Copy link

alizhan-plb commented Dec 31, 2024

Please try upgrade "grpc-js-reflection-client" to version 1.2.23

I still have the same error.

@gawsoftpl

@gawsoftpl
Copy link
Owner

Please try upgrade "grpc-js-reflection-client" to version 1.2.23

I still have the same error.

@gawsoftpl

Without access to grpc server I cannot resolve this issue.

@gawsoftpl
Copy link
Owner

/Users/marcus/balaena-quant/rbs/node_modules/.pnpm/[email protected]/node_modules/protobufjs/ext/descriptor/index.js:219

If you cannot give me access to your grpc server you should debug this file:
/Users/marcus/balaena-quant/rbs/node_modules/.pnpm/[email protected]/node_modules/protobufjs/ext/descriptor/index.js:219

This is a issue with protobufjs package and you have to check which grpc message has error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants