check error field in proto message

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2023-10-18 00:37:00 +03:00
parent a0385eff9c
commit 3806fb9336

View File

@ -1002,6 +1002,11 @@ func (g *Generator) writeErrors(plugin *protogen.Plugin) error {
return err
}
for _, field := range msg.Fields {
if field.GoName == "Error" {
return fmt.Errorf("failed generate Error() string interface for %s message %s already have Error field", field.Location.SourceFile, msg.Desc.Name())
}
}
gfile.P(`func (m *`, msg.GoIdent.GoName, `) Error() string {`)
gfile.P(`buf, _ := marshaler.Marshal(m)`)
gfile.P("return string(buf)")