3

protoc-gen-validate is a protoc plugin to generate polyglot message validators.

The project uses Bazel for builds and has an open pull request to add support for customization of validation error messages.

The original code was made in 2020. Recently it was updated with the latest code, and after fixing all merge conflicts now it fails to build, but I can't find the issue:

~/GitHub/protoc-gen-validate (i18n) $ make bazel-tests
bazel test //tests/... --test_output=errors
INFO: Analyzed 68 targets (0 packages loaded, 0 targets configured).
INFO: Found 62 targets and 6 test targets...
ERROR: /Users/mparnisari/GitHub/protoc-gen-validate/tests/harness/cases/BUILD:46:21: Generating into bazel-out/darwin-fastbuild/bin/tests/harness/cases/go_/github.com/envoyproxy/protoc-gen-validate/tests/harness/cases/go failed: (Exit 1): go-protoc-bin failed: error executing command bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/io_bazel_rules_go/go/tools/builders/go-protoc-bin_/go-protoc-bin -protoc bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/com_google_protobuf/protoc ... (remaining 117 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
[error] failed post-processing: 820:39: missing ',' in argument list (and 10 more errors)
--validate_out: protoc-gen-validate: Plugin failed with status code 1.
2021/12/14 23:46:43 error running protoc: exit status 1
ERROR: /Users/mparnisari/GitHub/protoc-gen-validate/tests/harness/cases/BUILD:46:21 GoCompilePkg tests/harness/cases/go.a failed: (Exit 1): go-protoc-bin failed: error executing command bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/io_bazel_rules_go/go/tools/builders/go-protoc-bin_/go-protoc-bin -protoc bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/com_google_protobuf/protoc ... (remaining 117 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
INFO: Elapsed time: 0.962s, Critical Path: 0.48s
INFO: 8 processes: 8 internal.
FAILED: Build did NOT complete successfully

Judging by the fact that the error ([error] failed post-processing: 820:39: missing ',' in argument list (and 10 more errors)) appears immediately after I fire the tests command, I figure this is an issue with Bazel, but I'm not sure.


UPDATE 1: I narrowed it down to this:

~/GitHub/fork/protoc-gen-validate (i18n) $ make testcases
cd tests/harness/cases && \
        protoc \
                -I . \
                -I ../../.. \
                --go_out="module=github.com/envoyproxy/protoc-gen-validate/tests/harness/cases/go,Mtests/harness/cases/other_package/embed.proto=github.com/envoyproxy/protoc-gen-validate/tests/harness/cases/other_package/go;other_package,Mtests/harness/cases/yet_another_package/embed.proto=github.com/envoyproxy/protoc-gen-validate/tests/harness/cases/yet_another_package/go,Mvalidate/validate.proto=github.com/envoyproxy/protoc-gen-validate/validate,Mgoogle/protobuf/any.proto=google.golang.org/protobuf/types/known/anypb,Mgoogle/protobuf/duration.proto=google.golang.org/protobuf/types/known/durationpb,Mgoogle/protobuf/struct.proto=google.golang.org/protobuf/types/known/structpb,Mgoogle/protobuf/timestamp.proto=google.golang.org/protobuf/types/known/timestamppb,Mgoogle/protobuf/wrappers.proto=google.golang.org/protobuf/types/known/wrapperspb,Mgoogle/protobuf/descriptor.proto=google.golang.org/protobuf/types/descriptorpb:./go" \
                --plugin=protoc-gen-go=/Users/mparnisari/go/bin/protoc-gen-go \
                --validate_out="module=github.com/envoyproxy/protoc-gen-validate/tests/harness/cases/go,lang=go,Mtests/harness/cases/other_package/embed.proto=github.com/envoyproxy/protoc-gen-validate/tests/harness/cases/other_package/go,Mtests/harness/cases/yet_another_package/embed.proto=github.com/envoyproxy/protoc-gen-validate/tests/harness/cases/yet_another_package/go:./go" \
                ./*.proto
filename-with-dash.proto:5:1: warning: Import validate/validate.proto is unused.
[error] failed post-processing: 820:39: missing ',' in argument list (and 10 more errors)
--validate_out: protoc-gen-validate: Plugin failed with status code 1.
make: 
*** [testcases] Error 1

UPDATE 2: narrowed it down. if I delete this file: tests/harness/cases/maps.proto

make testcases works


UPDATE 3: narrowed it down. if I remove these lines: https://github.com/envoyproxy/protoc-gen-validate/blob/main/tests/harness/cases/maps.proto#L14-L17

make testcase works

Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130

1 Answers1

1

Building with switch --sandbox_debug would provide an untruncated stacktrace.
It's all about one missing comma ...the only question is within which file and line.

It complains about the harness_py_proto tests @ 46:21. Running a syntax check on file tests/harness/executor/cases.go suggested, because if 820:39 isn't in some generated file, this might be the file which fits best (by line numbers and also the error message). I'm not that fluent in Go syntax, that's why I cannot spot it at sight - but a syntax checker or linter could:

lint bazel testcases bazel-tests

Also the Makefile might be a possible candidate, but there's not much going on:

.PHONY: harness
harness: testcases tests/harness/go/harness.pb.go tests/harness/go/main/go-harness tests/harness/cc/cc-harness bin/harness ## runs the test harness, validating a series of test cases in all supported languages
    ./bin/harness -go -cc

.PHONY: bazel-tests
bazel-tests: ## runs all tests with Bazel
    bazel test //tests/... --test_output=errors

Ever tried running make harness previously? When it does what the comment says ...

## runs the test harness, validating a series of test cases in all supported languages
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • "It complains about the harness_py_proto tests @ 46:21", where are you seeing this? – Maria Ines Parnisari Dec 17 '21 at 17:18
  • I've looked up given coordinates in the listing of changes. and frankly speaking, I'm not exactly certain if the comma is missing in the sources or the generated protos; both could be possible. And with limited language skills, the answer commonly is to use a linter, which knows how the syntax is supposed to look alike. And if not the answer, it might at least provide further clues, what the culprit could be. It might be easier to tell, when knowing which change broke the build ...vs. 24? changes, which broke the build. – Martin Zeitler Dec 18 '21 at 18:17
  • And I've merely looked at the tests, it could also be that they don't match the code too well anymore. And it does not necessarily have to be a missing comma, but could as well be related to missing or excess brackets, making it appears as if a comma would be missing, depending on the resulting syntax. However, when it complains about the syntax, this usually can be taken serious. – Martin Zeitler Dec 18 '21 at 18:28