From 014778b72a2086ace5eb7bdf3c7bb10205b68110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=85=E5=AD=90?= Date: Fri, 15 Oct 2021 17:18:13 +0800 Subject: [PATCH] fix(cmd/proto-gen-http): fix the problem that the field declaration does not exist causing panic (#1553) --- cmd/protoc-gen-go-http/http.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/protoc-gen-go-http/http.go b/cmd/protoc-gen-go-http/http.go index 4d2b4dd67..0d5e46495 100644 --- a/cmd/protoc-gen-go-http/http.go +++ b/cmd/protoc-gen-go-http/http.go @@ -161,6 +161,10 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path fields := m.Input.Desc.Fields() for _, v := range vars { fd := fields.ByName(protoreflect.Name(v)) + if fd == nil { + fmt.Fprintf(os.Stderr, "\u001B[31mERROR\u001B[m: The corresponding field '%s' declaration in message could not be found in '%s'\n", v, path) + os.Exit(2) + } if fd.IsMap() { fmt.Fprintf(os.Stderr, "\u001B[31mWARN\u001B[m: The field in path:'%s' shouldn't be a map.\n", v) }