protoc-gen-validate icon indicating copy to clipboard operation
protoc-gen-validate copied to clipboard

Unable to build validators "failed post-processing: 6:1: expected 'IDENT', found 'import'"

Open nikhilesh-payyavuala opened this issue 2 years ago • 1 comments

Created an example.proto

syntax = "proto3";

package examplepb;

import "validate/validate.proto";

option go_package= "rbac_proto/";

message Person {
  uint64 id    = 1 [(validate.rules).uint64.gt    = 999];

  string email = 2 [(validate.rules).string.email = true];

  string name  = 3 [(validate.rules).string = {
                      pattern:   "^[^[0-9]A-Za-z]+( [^[0-9]A-Za-z]+)*$",
                      max_bytes: 256,
                   }];

  Location home = 4 [(validate.rules).message.required = true];

  message Location {
    double lat = 1 [(validate.rules).double = { gte: -90,  lte: 90 }];
    double lng = 2 [(validate.rules).double = { gte: -180, lte: 180 }];
  }
}

And running the command in README.md gives the following error.

protoc \           
  -I . \
  -I ${GOPATH}/src \
  -I ${GOPATH}/src/github.com/envoyproxy/protoc-gen-validate \
  --go_out=":../generated" \
  --validate_out="lang=go:../generated" \
  example.proto

[error] failed post-processing: 6:1: expected 'IDENT', found 'import'
--validate_out: protoc-gen-validate: Plugin failed with status code 1.
> go version 
go version go1.18.2 darwin/arm64

> protoc --version
libprotoc 3.19.4

Please let me know if more information is required.

nikhilesh-payyavuala avatar Jun 09 '22 00:06 nikhilesh-payyavuala

Ran into this bug as well, appears that the option go_package including a trailing / is the problem. We were able to fix this by switching to an equivalent ./rbac_proto.

maxdubrinsky avatar Sep 14 '22 15:09 maxdubrinsky