hashicorp/nomad · error
Got 0 byte response with non-nil decode object
Error message
Got 0 byte response with non-nil decode object
What it means
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.
Source
Thrown at api/api.go:1232
header := resp.Header
// Parse the X-Nomad-Index
index, err := strconv.ParseUint(header.Get("X-Nomad-Index"), 10, 64)
if err != nil {
return fmt.Errorf("Failed to parse X-Nomad-Index: %v", err)
}
q.LastIndex = index
return nil
}
// decodeBody is used to JSON decode a body
func decodeBody(resp *http.Response, out any) error {
switch resp.ContentLength {
case 0:
if out == nil {
return nil
}
return errors.New("Got 0 byte response with non-nil decode object")
default:
dec := json.NewDecoder(resp.Body)
return dec.Decode(out)
}
}
// encodeBody prepares the reader to serve as the request body.
//
// Returns the `obj` input if it is a raw io.Reader object; otherwise
// returns a reader of the json format of the passed argument.
func encodeBody(obj any) (io.Reader, error) {
if reader, ok := obj.(io.Reader); ok {
return reader, nil
}
buf := bytes.NewBuffer(nil)
enc := json.NewEncoder(buf)
if err := enc.Encode(obj); err != nil {View on GitHub (pinned to 482b49bf1a)
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at api/api.go:1232 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/df40bdd357a949ea.
Report an issue: GitHub.