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

Error: duplicate name 'constructor' in Type #1113

Open
meandthemoon opened this issue Sep 25, 2018 · 3 comments
Open

Error: duplicate name 'constructor' in Type #1113

meandthemoon opened this issue Sep 25, 2018 · 3 comments
Labels

Comments

@meandthemoon
Copy link

protobuf.js version: 6.8.8

I'm implementing a Node.js client to a service that communicates via protobuf messages. The message contents hold code-related information. For instance, there is a protobuf model similar to the following that represents the context of a function call:

// models.proto
package my.models;

message FunctionCallContext {
    string method_name = 1;
    repeated string arguments = 2;
    bool constructor = 3;
    // etc
}

It appears that the constructor field is causing conflict when I load the models from its .proto file. From a shallow investigation, it looks like the validation is failing simply because the library provides each Message with an identically-named property: https://github.com/dcodeIO/protobuf.js/blob/master/src/type.js#L162

So does this mean the field name is off limits should I choose to use this library? Are there others? Should this be remedied or just documented? Maybe this is an edge case scenario but it seems unfortunate. Also, I don't manage the models, so a "fix" involving an edit to the .proto isn't available to me.

Reproduction:
With the model example above, either

require('protobufjs').load(models.proto).then(/* */);

or

pbjs -t json models.proto > bundle.json

will result in

Error: duplicate name 'constructor' in Type FunctionCallContext
    at Type.add (/Users/matthewhenry/workspace/cs/contrast-node-protect/core/node_modules/protobufjs/src/type.js:331:15)
    at parseField (/Users/matthewhenry/workspace/cs/contrast-node-protect/core/node_modules/protobufjs/src/parse.js:378:16)
    at parseType_block (/Users/matthewhenry/workspace/cs/contrast-node-protect/core/node_modules/protobufjs/src/parse.js:338:21)
    at ifBlock (/Users/matthewhenry/workspace/cs/contrast-node-protect/core/node_modules/protobufjs/src/parse.js:286:17)
    at parseType (/Users/matthewhenry/workspace/cs/contrast-node-protect/core/node_modules/protobufjs/src/parse.js:304:9)
    at parseCommon (/Users/matthewhenry/workspace/cs/contrast-node-protect/core/node_modules/protobufjs/src/parse.js:259:17)
    at parse (/Users/matthewhenry/workspace/cs/contrast-node-protect/core/node_modules/protobufjs/src/parse.js:728:21)
    at process (/Users/matthewhenry/workspace/cs/contrast-node-protect/core/node_modules/protobufjs/src/root.js:107:30)
    at fetch (/Users/matthewhenry/workspace/cs/contrast-node-protect/core/node_modules/protobufjs/src/root.js:166:13)
    at Root.load (/Users/matthewhenry/workspace/cs/contrast-node-protect/core/node_modules/protobufjs/src/root.js:194:13)

Commenting out the constructor field of the model will allow the commands to execute without error.

@QuentinBrosse
Copy link

Hi,

Does someone have an idea of how to fix it? :)

@dm03514
Copy link

dm03514 commented Apr 6, 2020

Is it possible to address this? What would an acceptable fix be? If there are JS specific fields that are off limits (ie constructor) would it be possible for protobuf.js to manage those and alias them?

for example it protobuf.js hits a reserved word/method/property/etc could it mangle the name of the protobuf property, and keep track of the original name for serialization/deserialization?

@Ruithlzz09
Copy link

Hi , I am facing same issue
Although Issue can be fixed by renaming that variable instead of using reserved word but I prefer if there is some way to bypass this check

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

No branches or pull requests

5 participants