{"record":{"id":"df40bdd357a949ea","repo":"hashicorp/nomad","slug":"got-0-byte-response-with-non-nil-decode-object","errorCode":null,"errorMessage":"Got 0 byte response with non-nil decode object","messagePattern":"Got 0 byte response with non-nil decode object","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/api.go","lineNumber":1232,"sourceCode":"\theader := resp.Header\n\n\t// Parse the X-Nomad-Index\n\tindex, err := strconv.ParseUint(header.Get(\"X-Nomad-Index\"), 10, 64)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to parse X-Nomad-Index: %v\", err)\n\t}\n\tq.LastIndex = index\n\treturn nil\n}\n\n// decodeBody is used to JSON decode a body\nfunc decodeBody(resp *http.Response, out any) error {\n\tswitch resp.ContentLength {\n\tcase 0:\n\t\tif out == nil {\n\t\t\treturn nil\n\t\t}\n\t\treturn errors.New(\"Got 0 byte response with non-nil decode object\")\n\tdefault:\n\t\tdec := json.NewDecoder(resp.Body)\n\t\treturn dec.Decode(out)\n\t}\n}\n\n// encodeBody prepares the reader to serve as the request body.\n//\n// Returns the `obj` input if it is a raw io.Reader object; otherwise\n// returns a reader of the json format of the passed argument.\nfunc encodeBody(obj any) (io.Reader, error) {\n\tif reader, ok := obj.(io.Reader); ok {\n\t\treturn reader, nil\n\t}\n\n\tbuf := bytes.NewBuffer(nil)\n\tenc := json.NewEncoder(buf)\n\tif err := enc.Encode(obj); err != nil {","sourceCodeStart":1214,"sourceCodeEnd":1250,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/api/api.go#L1214-L1250","documentation":"decodeBody guard: the HTTP response has ContentLength 0 but a non-nil decode target was supplied, so there is no body to JSON-decode. Indicates an unexpected empty response from the server for an API call that should return data.","triggerScenarios":"Thrown at api/api.go:1232 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the Nomad server version/endpoint — the endpoint may legitimately return an empty body","Pass nil as the out object if the response is expected to be empty","Inspect server logs for a handler that failed to write a body"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}