{"record":{"id":"25efb09dbba362ec","repo":"t8y2/dbx","slug":"key-is-required","errorCode":null,"errorMessage":"Key is required","messagePattern":"Key is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd-go/kv.go","lineNumber":496,"sourceCode":"\treturn base64.StdEncoding.EncodeToString(next)\n}\n\nfunc keyBytesParam(params map[string]json.RawMessage) (string, error) {\n\tif encoded := rawObject(params, \"keyBytes\"); encoded != nil {\n\t\tvalue, err := parseValueObject(encoded)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\treturn value, nil\n\t}\n\tif raw, ok := params[\"key\"]; ok && raw != nil && string(raw) != \"null\" {\n\t\tvar key string\n\t\tif err := json.Unmarshal(raw, &key); err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\treturn key, nil\n\t}\n\treturn \"\", errors.New(\"Key is required\")\n}\n\nfunc rawObject(params map[string]json.RawMessage, key string) map[string]json.RawMessage {\n\traw := params[key]\n\tif len(raw) == 0 || string(raw) == \"null\" {\n\t\treturn nil\n\t}\n\tvar object map[string]json.RawMessage\n\tif err := json.Unmarshal(raw, &object); err != nil || object == nil {\n\t\treturn nil\n\t}\n\treturn object\n}\n\nfunc bytesObject(bytes []byte) map[string]any {\n\treturn map[string]any{\n\t\t\"encoding\": \"base64\",\n\t\t\"data\":     base64.StdEncoding.EncodeToString(bytes),","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd-go/kv.go#L478-L514","documentation":"keyBytesParam is the shared parameter decoder for all key-based kv operations (get, put, delete, rename, history, authRolePermission). It requires a \"key\" parameter that unmarshals into a JSON string; if the parameter is missing or is not a string, it returns the plain error \"Key is required\". This is a client-side request-validation error, raised before any network call to etcd.","triggerScenarios":"Calling any of get/put/delete/rename/history/authRolePermission without a \"key\" field in params, with key set to null, or with a non-string JSON value (number, object, array) at kv.go:496.","commonSituations":"Typo in the parameter name (e.g. sending \"k\" or \"name\" instead of \"key\"); passing a raw (unquoted) string through a JSON layer that then fails to unmarshal into string; building params programmatically and forgetting the key field.","solutions":["Include a \"key\" field as a JSON string in the params of the kv call.","Verify the parameter is spelled exactly \"key\" and is quoted as a JSON string, not a number or object.","Validate/serialize params before dispatch (e.g. marshal a struct with a required Key string field)."],"exampleFix":"// before: missing/wrong-typed key\nagent.call(\"get\", {\"k\": 42})\n\n// after: required string key\nagent.call(\"get\", {\"key\": \"cfg/a\"})","handlingStrategy":"validation","validationCode":"func requireKey(params map[string]any) (string, error) {\n    k, ok := params[\"key\"]\n    if !ok { return \"\", errors.New(\"params.key is required\") }\n    s, isStr := k.(string)\n    if !isStr || s == \"\" { return \"\", errors.New(\"params.key must be a non-empty string\") }\n    return s, nil\n}","typeGuard":"func keyParam(v any) (string, bool) {\n    s, ok := v.(string)\n    return s, ok && s != \"\"\n}","tryCatchPattern":null,"preventionTips":["Always send \"key\" as a quoted JSON string.","Wrap kv calls in helpers that build params from typed structs.","Check field names carefully: 'key', not 'k' or 'name'."],"tags":["etcd","validation","missing-parameter","rpc"],"backgroundTag":"missing-required-parameter","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}