{"record":{"id":"07e336384f86092d","repo":"micro/go-micro","slug":"message-passed-in-is-nil","errorCode":null,"errorMessage":"message passed in is nil","messagePattern":"message passed in is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"transport/http_client.go","lineNumber":108,"sourceCode":"\t\t}\n\t\th.Unlock()\n\t}\n\n\t// set timeout if its greater than 0\n\tif h.ht.opts.Timeout > time.Duration(0) {\n\t\tif err := h.conn.SetDeadline(time.Now().Add(h.ht.opts.Timeout)); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn req.Write(h.conn)\n\n}\n\n// Recv receives a message.\nfunc (h *httpTransportClient) Recv(msg *Message) (err error) {\n\tif msg == nil {\n\t\treturn errors.New(\"message passed in is nil\")\n\t}\n\n\tvar req *http.Request\n\n\tif !h.dialOpts.Stream {\n\n\t\tvar rc *http.Request\n\t\tvar ok bool\n\n\t\th.Lock()\n\t\tselect {\n\t\tcase rc, ok = <-h.req:\n\t\tdefault:\n\t\t}\n\n\t\tif !ok {\n\t\t\tif len(h.reqList) == 0 {\n\t\t\t\th.Unlock()","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/transport/http_client.go#L90-L126","documentation":"httpTransportClient.Recv requires a non-nil *Message to fill with the incoming response body and headers. Passing nil means the caller has nowhere to put the received data, so the transport refuses immediately with 'message passed in is nil'.","triggerScenarios":"Calling client.Recv(nil) directly, or a loop that reuses a msg variable that was never allocated (e.g. var msg *Message declared but not initialized before Recv).","commonSituations":"Copy-pasted socket code where Recv allocates internally vs client code where the caller must allocate; nil returned from an earlier failed allocation and reused; refactor that dropped the &Message{} initialization.","solutions":["Allocate the message before receiving: msg := &transport.Message{} then client.Recv(msg)","Audit call sites so Recv is never handed a variable that can be nil","If a helper returns the message, check that helper's error/nil return before passing it on"],"exampleFix":"// before\nvar msg *transport.Message\nclient.Recv(msg) // error: message passed in is nil\n// after\nmsg := &transport.Message{}\nif err := client.Recv(msg); err != nil { return err }","handlingStrategy":"validation","validationCode":"if msg == nil {\n\tmsg = &transport.Message{}\n}\nerr := client.Recv(msg)","typeGuard":"func messageReady(m *transport.Message) bool { return m != nil }","tryCatchPattern":"if err := client.Recv(msg); err != nil {\n\tif strings.Contains(err.Error(), \"message passed in is nil\") {\n\t\t// fix call site: allocate message\n\t}\n}","preventionTips":["Always allocate &transport.Message{} before Recv","In loops, create a new message per iteration","Let helpers never return a nil message alongside a nil error"],"tags":["transport","http","nil-argument"],"backgroundTag":"nil-message-argument","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}