Error whilst testing serve.proto
dheerajbhadani opened this issue · comments
$ letmegrpc --addr=localhost:12345 --port=8080 serve.proto
2018/08/18 12:21:51 protoc-gen-gogo: program not found or is not executable
--gogo_out: protoc-gen-gogo: Plugin failed with status code 1.
Have you run the installation instructions?
Indeed. I tried the installation steps first and then the above mentioned command.
Ok then there is a step missing, could you try?
go install github.com/gogo/protobuf/protoc-gen-gogo
I think so. After trying the above-mentioned command, it seems worked out. However, got another error whilst running letmegrpc command.
Here is the new terminal output for your reference:
2018/08/19 19:15:30 panic: assignment to entry in nil map
goroutine 1 [running]:
github.com/gogo/protobuf/protoc-gen-gogo/generator.(*Generator).RecordTypeUse(0xc4200d88c0, 0xc42009a6b0, 0xc)
/Users/dbh/go/src/github.com/gogo/protobuf/protoc-gen-gogo/generator/generator.go:1977 +0xd4
github.com/gogo/letmegrpc/html.(*html).Generate(0xc42010b960, 0xc4200a88f0)
/Users/dbh/go/src/github.com/gogo/letmegrpc/html/html.go:191 +0x28b2
github.com/gogo/protobuf/protoc-gen-gogo/generator.(*Generator).generatePlugin(0xc4200d88c0, 0xc4200a88f0, 0x12c7380, 0xc42010b960)
/Users/dbh/go/src/github.com/gogo/protobuf/protoc-gen-gogo/generator/helper.go:347 +0x93
github.com/gogo/protobuf/protoc-gen-gogo/generator.(*Generator).GeneratePlugin(0xc4200d88c0, 0x12c7380, 0xc42010b960)
/Users/dbh/go/src/github.com/gogo/protobuf/protoc-gen-gogo/generator/helper.go:331 +0x284
main.main()
/Users/dbh/go/src/github.com/gogo/letmegrpc/protoc-gen-letmegrpc/main.go:59 +0x224
--letmegrpc_out: protoc-gen-letmegrpc: Plugin failed with status code 2.
exit status 1
Could I see your .proto file?
I expect that it might have an embedded message or enum which is not supported
Sure. I am using serve.proto(https://github.com/gogo/letmegrpc/blob/master/testcmd/serve.proto) which is mentioned in README.md.
whop whop :(
I am getting the same, must have to do with the newer version of gogoprotobuf.
Actually this does not work with the newest version of gogoprotobuf on many levels.
Could you try using it with v1.0.0 instead?
Or would you like to contribute a fix?
If not, then please let me know, so I can work on a fix.
No problem at all :)
This fix will involves both letmegrpc and gogoprotobuf.
First you will need to make sure that gogoprotobuf does not panic, by doing a nil check for the map and creating the map, where the error occurs. This will hopefully allow you to generate some code for letmegrpc, but it will not be working code yet.
But the hope is that this will lead you to an answer.
Next you will be able to do some easy fixes to letmegrpc tests by specifying some field names in constructors. The compiler will lead you here.
Now you will find that gogoprotobuf (probably me) removed a SetFile method from the generator. This is how far I got. I was looking for the diff and saw that this was going to be a small project to fix this.
Are you still game or do you want me to take it?
Hi Walter,
Thanks for the detail information. Considering the current constraint, I am afraid, I won't be able to make this quick so it would be great if you could take this on, please.
Cheers,
Dheeraj
The changes to gogoprotobuf have been proposed
Other changes required will be
--- a/form/form_test.go
+++ b/form/form_test.go
@@ -60,7 +60,7 @@ func TestCreateCustom(t *testing.T) {
g.SetPackageNames()
g.BuildTypeNameMap()
g.Reset()
- g.SetFile(desc.File[0])
+ g.SetFile(desc.File[0].GetName())
formStr = CreateCustom("WeirdMethod", "weird.form", "Weird", g, CustomBuildField)
testserver := httptest.NewServer(http.HandlerFunc(handle))
defer testserver.Close()
diff --git a/test/html_test.go b/test/html_test.go
index 6ee3386..97324df 100644
--- a/test/html_test.go
+++ b/test/html_test.go
@@ -44,11 +44,11 @@ import (
type aServer struct{}
func (this *aServer) UnaryCall(c context.Context, s *MyRequest) (*MyResponse, error) {
- return &MyResponse{s.Value}, nil
+ return &MyResponse{Value: s.Value}, nil
}
func (this *aServer) Downstream(m *MyRequest, s MyTest_DownstreamServer) error {
for i := 0; i < int(m.Value); i++ {
- err := s.Send(&MyMsg{int64(i)})
+ err := s.Send(&MyMsg{Value: int64(i)})
if err != nil {
return err
}
@@ -62,7 +62,7 @@ func (this *aServer) Upstreamy(s MyTest_UpstreamyServer) error {
sum += rec.Value
rec, err = s.Recv()
}
- return s.SendAndClose(&MyResponse{sum})
+ return s.SendAndClose(&MyResponse{Value: sum})
}
func (this *aServer) Bidi(b MyTest_BidiServer) error {
var err error
@@ -72,7 +72,7 @@ func (this *aServer) Bidi(b MyTest_BidiServer) error {
if err != nil {
break
}
- err = b.Send(&MyMsg2{msg.Value})
+ err = b.Send(&MyMsg2{Value: msg.Value})
if err != nil {
break
}
@@ -125,7 +125,7 @@ func TestHTML(t *testing.T) {
t.Fatal("no form")
}
want := int64(5)
- req := &MyRequest{want, 0}
+ req := &MyRequest{Value: want, Value2: 0}
data, err := json.Marshal(req)
if err != nil {
t.Fatal(err)
And we can also make this cleanup
diff --git a/protoc-gen-letmegrpc/main.go b/protoc-gen-letmegrpc/main.go
index 63890e5..d1f65b1 100644
--- a/protoc-gen-letmegrpc/main.go
+++ b/protoc-gen-letmegrpc/main.go
@@ -26,49 +26,12 @@
package main
import (
- "io/ioutil"
- "os"
- "strings"
-
"github.com/gogo/letmegrpc/html"
- "github.com/gogo/protobuf/proto"
- "github.com/gogo/protobuf/protoc-gen-gogo/generator"
+ "github.com/gogo/protobuf/vanity/command"
)
func main() {
- gen := generator.New()
-
- data, err := ioutil.ReadAll(os.Stdin)
- if err != nil {
- gen.Error(err, "reading input")
- }
-
- if err := proto.Unmarshal(data, gen.Request); err != nil {
- gen.Error(err, "parsing input proto")
- }
-
- if len(gen.Request.FileToGenerate) == 0 {
- gen.Fail("no files to generate")
- }
-
- gen.CommandLineParameters(gen.Request.GetParameter())
-
- gen.WrapTypes()
- gen.SetPackageNames()
- gen.BuildTypeNameMap()
- gen.GeneratePlugin(html.New())
-
- for i := 0; i < len(gen.Response.File); i++ {
- gen.Response.File[i].Name = proto.String(strings.Replace(*gen.Response.File[i].Name, ".pb.go", ".letmegrpc.go", -1))
- }
-
- // Send back the results.
- data, err = proto.Marshal(gen.Response)
- if err != nil {
- gen.Error(err, "failed to marshal output proto")
- }
- _, err = os.Stdout.Write(data)
- if err != nil {
- gen.Error(err, "failed to write output proto")
- }
+ req := command.Read()
+ resp := command.GeneratePlugin(req, html.New(), ".letmegrpc.go")
+ command.Write(resp)
}
The fix has been pushed
This should now work with the newest gogoprotobuf, not v1.1, but the newest commit.
These changes to gogoprotobuf were required