{"record":{"id":"f3f7a085f8878866","repo":"cayleygraph/cayley","slug":"cannot-remove-nil-value","errorCode":null,"errorMessage":"cannot remove nil value","messagePattern":"cannot remove nil value","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/http/api_v2.go","lineNumber":332,"sourceCode":"\t\tjsonResponse(w, http.StatusBadRequest, fmt.Errorf(\"format is not supported for reading nodes\"))\n\t\treturn\n\t}\n\tconst limit = 128*1024 + 1\n\trd := io.LimitReader(r.Body, limit)\n\tdata, err := ioutil.ReadAll(rd)\n\tif err != nil {\n\t\tjsonResponse(w, http.StatusBadRequest, err)\n\t\treturn\n\t} else if len(data) == limit {\n\t\tjsonResponse(w, http.StatusBadRequest, fmt.Errorf(\"request data is too large\"))\n\t\treturn\n\t}\n\tv, err := format.UnmarshalValue(data)\n\tif err != nil {\n\t\tjsonResponse(w, http.StatusBadRequest, err)\n\t\treturn\n\t} else if v == nil {\n\t\tjsonResponse(w, http.StatusBadRequest, fmt.Errorf(\"cannot remove nil value\"))\n\t\treturn\n\t}\n\th, err := api.handleForRequest(r)\n\tif err != nil {\n\t\tjsonResponse(w, http.StatusBadRequest, err)\n\t\treturn\n\t}\n\terr = h.RemoveNode(v)\n\tif err != nil {\n\t\tjsonResponse(w, http.StatusInternalServerError, err)\n\t\treturn\n\t}\n\tw.Header().Set(hdrContentType, contentTypeJSON)\n\tconst n = 1\n\tfmt.Fprintf(w, `{\"result\": \"Successfully deleted %d nodes.\", \"count\": %d}`+\"\\n\", n, n)\n}\n\ntype checkWriter struct {","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/server/http/api_v2.go#L314-L350","documentation":"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'.","triggerScenarios":"Sending an empty body or the literal `null` to /api/v2/node/delete so format.UnmarshalValue returns a nil interface.","commonSituations":"curl calls with -d '' or -d 'null'; HTTP clients serializing undefined/None variables as null; test harnesses invoking the endpoint without a payload.","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."],"exampleFix":"// before\ncurl -X POST -H 'Content-Type: application/json' -d 'null' http://localhost:64210/api/v2/node/delete\n// after\ncurl -X POST -H 'Content-Type: application/json' -d '{\"id\":\"alice\"}' http://localhost:64210/api/v2/node/delete","handlingStrategy":"validation","validationCode":"if len(body) == 0 || string(body) == \"null\" || payload == nil {\n    return errors.New(\"node delete requires a non-null JSON value\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["http","null-value","cayley","api"],"backgroundTag":"null-argument","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}