cayleygraph/cayley · error
cannot remove nil value
Error message
cannot remove nil value
What it means
After unmarshaling the DELETE body, ServeNodeDelete checks whether the decoded value is nil. An empty body or the JSON literal `null` decodes to a nil Go value, and a removal cannot be performed against a nil value, so the API returns 400 'cannot remove nil value'.
Source
Thrown at server/http/api_v2.go:332
jsonResponse(w, http.StatusBadRequest, fmt.Errorf("format is not supported for reading nodes"))
return
}
const limit = 128*1024 + 1
rd := io.LimitReader(r.Body, limit)
data, err := ioutil.ReadAll(rd)
if err != nil {
jsonResponse(w, http.StatusBadRequest, err)
return
} else if len(data) == limit {
jsonResponse(w, http.StatusBadRequest, fmt.Errorf("request data is too large"))
return
}
v, err := format.UnmarshalValue(data)
if err != nil {
jsonResponse(w, http.StatusBadRequest, err)
return
} else if v == nil {
jsonResponse(w, http.StatusBadRequest, fmt.Errorf("cannot remove nil value"))
return
}
h, err := api.handleForRequest(r)
if err != nil {
jsonResponse(w, http.StatusBadRequest, err)
return
}
err = h.RemoveNode(v)
if err != nil {
jsonResponse(w, http.StatusInternalServerError, err)
return
}
w.Header().Set(hdrContentType, contentTypeJSON)
const n = 1
fmt.Fprintf(w, `{"result": "Successfully deleted %d nodes.", "count": %d}`+"\n", n, n)
}
type checkWriter struct {View on GitHub (pinned to 81dcd7d73e)
Solutions
- Send a concrete JSON value, e.g. {"id":"<node-id>"}, describing what to remove.
- Fix client code so the node identifier is populated and non-null before the request is sent.
- Verify the Content-Type matches the payload format so the body parses into the intended value.
Example fix
// before
curl -X POST -H 'Content-Type: application/json' -d 'null' http://localhost:64210/api/v2/node/delete
// after
curl -X POST -H 'Content-Type: application/json' -d '{"id":"alice"}' http://localhost:64210/api/v2/node/delete Defensive patterns
Strategy: validation
Validate before calling
if len(body) == 0 || string(body) == "null" || payload == nil {
return errors.New("node delete requires a non-null JSON value")
} Prevention
- Never send an empty or literal-null body to node/delete.
- Validate the target node id is non-empty before serializing.
- Ensure HTTP clients don't serialize undefined variables as null.
- Add an integration test asserting a valid delete body.
When it happens
Trigger: Sending an empty body or the literal `null` to /api/v2/node/delete so format.UnmarshalValue returns a nil interface.
Common situations: curl calls with -d '' or -d 'null'; HTTP clients serializing undefined/None variables as null; test harnesses invoking the endpoint without a payload.
Related errors
- request data is too large
- format is not supported for reading quads
- format is not supported for reading nodes
- no support for HTTP interface for this query language
- request is too large
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/f3f7a085f8878866.
Report an issue: GitHub.