protobuf.js icon indicating copy to clipboard operation
protobuf.js copied to clipboard

Fails to parse "{" in options

Open kpritam-tw opened this issue 1 year ago • 5 comments

protobuf.js version: 1.1.1

Fails to parse following option


option (scalapb.options) = {
  field_transformations: [
    { // <--- parsing fails here
      when: {options: {[validate.rules] {message: {required: true}}}}
      set: {
        [scalapb.field] {
          required: true
        }
      }
    }
  ]
};
usr/local/lib/node_modules/protobufjs-cli/pbjs.js:254
            throw err;
            ^

Error: illegal value '{' (../target/x.proto, line 15)
    at illegal (/usr/local/lib/node_modules/protobufjs-cli/node_modules/protobufjs/src/parse.js:96:16)
    at readValue (/usr/local/lib/node_modules/protobufjs-cli/node_modules/protobufjs/src/parse.js:135:19)
    at parseOptionValue (/usr/local/lib/node_modules/protobufjs-cli/node_modules/protobufjs/src/parse.js:630:41)
    at parseOption (/usr/local/lib/node_modules/protobufjs-cli/node_modules/protobufjs/src/parse.js:600:27)
    at parse (/usr/local/lib/node_modules/protobufjs-cli/node_modules/protobufjs/src/parse.js:822:17)
    at process (/usr/local/lib/node_modules/protobufjs-cli/node_modules/protobufjs/src/root.js:127:30)
    at fetch (/usr/local/lib/node_modules/protobufjs-cli/node_modules/protobufjs/src/root.js:179:13)
    at Root.load (/usr/local/lib/node_modules/protobufjs-cli/node_modules/protobufjs/src/root.js:207:13)
    at Root.loadSync (/usr/local/lib/node_modules/protobufjs-cli/node_modules/protobufjs/src/root.js:248:17)
    at Object.main (/usr/local/lib/node_modules/protobufjs-cli/pbjs.js:245:18)

Node.js v19.8.1

kpritam-tw avatar Mar 23 '23 05:03 kpritam-tw

Is there a reason that this is not being addressed? In earlier versions it was the the "[" that threw the error. But this is valid proto definition https://protobuf.com/docs/language-spec#resolving-option-names

dependencies

dependencies: @grpc/grpc-js 1.9.3 └─┬ @grpc/proto-loader 0.7.9 └── protobufjs 7.2.5 @grpc/proto-loader 0.7.5 └── protobufjs 7.2.5 google-proto-files 4.0.0 └── protobufjs 7.2.5 ts-proto 1.155.1 ├── protobufjs 7.2.5 └─┬ ts-proto-descriptors 1.14.0 └── protobufjs 7.2.5

marsh73 avatar Sep 15 '23 01:09 marsh73

from the protobufjs docs on resolving optional names, here is an example that i don't see captured in your tests... https://protobuf.com/docs/language-spec#resolving-option-names

option (google.api.http) = {
    custom: {
        kind: "FETCH"
        path: "/foo/bar/baz/{id}"
    }
    additional_bindings: [
      {
          get: "/foo/bar/baz/{id}"
      },
      {
          post: "/foo/bar/baz/"
          body: "*"
      }
    ]
};

previously, this threw an error for the [ being present. Now that is fixed, but it doesn't seem to like the '{' inside the '['.

Error: illegal value '{'

marsh73 avatar Sep 15 '23 14:09 marsh73

@kpritam-tw did you ever find a solution? I have only been able to get it working by refactoring my proto definitions to use the original verbose format for declaring multiple option names

marsh73 avatar Sep 25 '23 20:09 marsh73

@kpritam-tw did you ever find a solution? I have only been able to get it working by refactoring my proto definitions to use the original verbose format for declaring multiple option names

Not really, the workaround is to move that piece of configuration in package.proto file. In that case, scala applies those configurations and on the js side, you can parse the file without package.proto

kpritam-tw avatar Sep 25 '23 20:09 kpritam-tw

i think the problem is that i'm consuming proto source files from a backend service i don't own... so i can't just move files around. using those files more as a contract for the service itsefl

marsh73 avatar Sep 27 '23 19:09 marsh73