From e9965f51092ef287b3ea0a8075c4fc359d37a47a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 22 Sep 2025 08:52:33 -0500 Subject: [PATCH] error out if server returns nil --- generateHTTP.go | 47 ++++------------------------------------------- protoParse.go | 1 + 2 files changed, 5 insertions(+), 43 deletions(-) diff --git a/generateHTTP.go b/generateHTTP.go index db0ee30..15cbb54 100644 --- a/generateHTTP.go +++ b/generateHTTP.go @@ -38,7 +38,6 @@ func (pb *Files) makeHTTPFile(pf *File) error { } } - fmt.Fprintf(newf, "\n") fmt.Fprintf(newf, "// END HTTP\n") return nil } @@ -119,50 +118,12 @@ func httpPost(w io.Writer, FRUITS string, fRUITS string) { fmt.Fprintln(w, " return nil, nil, err") fmt.Fprintln(w, " }") fmt.Fprintln(w, "") + fmt.Fprintln(w, " if len(reqPB.ServerData) == 0 {") + fmt.Fprintln(w, " return nil, reqPB, fmt.Errorf(\"server returned len(data)=0\")") + fmt.Fprintln(w, " }") + fmt.Fprintln(w, "") fmt.Fprintln(w, " newpb := new("+FRUITS+")") fmt.Fprintln(w, " err = newpb.Unmarshal(reqPB.ServerData)") fmt.Fprintln(w, " return newpb, reqPB, err") fmt.Fprintln(w, "}") } - -func httpCustomOld(w io.Writer, FRUITS string, fRUITS string, FRUIT string) { - fmt.Fprintln(w, "// err handling here isn't great") - fmt.Fprintln(w, "func (p *"+FRUITS+") HttpPost(baseURL string, route string) (*"+FRUITS+", *httppb.HttpRequest, error) {") - fmt.Fprintln(w, " // if you ever have 'http://www.wit.com//' GO will regect the server recieving it.") - fmt.Fprintln(w, " // Even though the linux kernel gets the network payload") - fmt.Fprintln(w, " // also it never gives you an error about that, it just goes away invisably inside GO") - fmt.Fprintln(w, " tmpURL, _ := url.Parse(baseURL) // 'http://forge.grid.wit.com:2520')") - fmt.Fprintln(w, " finalURL := tmpURL.JoinPath(\"/"+fRUITS+"/\", route)") - fmt.Fprintln(w, "") - fmt.Fprintln(w, " data, _ := p.Marshal()") - fmt.Fprintln(w, "") - fmt.Fprintln(w, " var err error") - fmt.Fprintln(w, " var req *http.Request") - fmt.Fprintln(w, "") - fmt.Fprintln(w, " req, err = http.NewRequest(http.MethodPost, finalURL.String(), bytes.NewBuffer(data))") - fmt.Fprintln(w, " if req == nil {") - fmt.Fprintln(w, " return nil, nil, err") - fmt.Fprintln(w, " }") - fmt.Fprintln(w, "") - fmt.Fprintln(w, " usr, _ := user.Current()") - fmt.Fprintln(w, " req.Header.Set(\"author\", usr.Username)") - fmt.Fprintln(w, " hostname, _ := os.Hostname()") - fmt.Fprintln(w, " req.Header.Set(\"hostname\", hostname)") - fmt.Fprintln(w, "") - fmt.Fprintln(w, " newdata, err := httppb.PostReq(req)") - fmt.Fprintln(w, "") - fmt.Fprintln(w, " reqPB, err2 := httppb.ReqToPB(req)") - fmt.Fprintln(w, " reqPB.URL = finalURL.String()") - fmt.Fprintln(w, " if err != nil {") - fmt.Fprintln(w, " // reqPB.Errors = append(reqPB.Errors, fmt.Sprintf(err))") - fmt.Fprintln(w, " }") - fmt.Fprintln(w, " if err2 != nil {") - fmt.Fprintln(w, " // reqPB.Errors = append(reqPB.Errors, fmt.Sprintf(err2))") - fmt.Fprintln(w, " }") - fmt.Fprintln(w, "") - fmt.Fprintln(w, " newpb := New"+FRUITS+"()") - fmt.Fprintln(w, " err = newpb.Unmarshal(newdata)") - fmt.Fprintln(w, "") - fmt.Fprintln(w, " return newpb, reqPB, err") - fmt.Fprintln(w, "}") -} diff --git a/protoParse.go b/protoParse.go index 37c1df2..474028c 100644 --- a/protoParse.go +++ b/protoParse.go @@ -197,6 +197,7 @@ func (pf *File) parseForMessage(line string) *MsgName { log.Info("got autogenpb:http") pf.DoHTTP = true msg.DoHTTP = true + msg.DoMarshal = true // http requires Marshal } if strings.Contains(line, "`autogenpb:gui") { log.Info("got autogenpb:gui")