{"record":{"id":"b6c5bdc2a6993fd8","repo":"t8y2/dbx","slug":"etcd-s-required-b6c5bd","errorCode":"ETCD_%s_REQUIRED","errorMessage":"ETCD_%s_REQUIRED","messagePattern":"ETCD_(.+?)_REQUIRED","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd2-go/kv.go","lineNumber":521,"sourceCode":"\treturn value\n}\n\nfunc longOrNull(params map[string]json.RawMessage, key string) *int64 {\n\traw := params[key]\n\tif len(raw) == 0 || string(raw) == \"null\" {\n\t\treturn nil\n\t}\n\tvar value int64\n\tif err := json.Unmarshal(raw, &value); err != nil {\n\t\treturn nil\n\t}\n\treturn &value\n}\n\nfunc requiredString(params map[string]json.RawMessage, field string) (string, error) {\n\tvalue := stringOrNull(params, field)\n\tif value == nil || *value == \"\" {\n\t\treturn \"\", fmt.Errorf(\"ETCD_%s_REQUIRED\", strings.ToUpper(field))\n\t}\n\treturn *value, nil\n}\n","sourceCodeStart":503,"sourceCodeEnd":525,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd2-go/kv.go#L503-L525","documentation":"requiredString builds a per-field error of the form ETCD_<FIELD>_REQUIRED (field uppercased) when a mandatory string parameter is missing, null, or empty in the JSON-RPC params. It backs the auth methods: authUserGet, authUserAdd, authUserDelete, authUserChangePassword, authUserGrantRevokeRole, authRoleGet.","triggerScenarios":"Calling e.g. authUserAdd without a 'user' field, authChangePassword without 'password', or passing \"\" for any required field — the message interpolates the field name (e.g. ETCD_USER_REQUIRED, ETCD_PASSWORD_REQUIRED).","commonSituations":"Partially filled RPC payloads, empty-string defaults sent by client tooling, omitted optional-looking fields that are actually mandatory for auth operations.","solutions":["Read the field name from the error code and supply a non-empty value for it.","Validate the params object client-side before invoking the auth method.","Ensure your client sends JSON strings, not null, for required fields."],"exampleFix":"// before\nauthUserAdd({\"password\": \"s3cret\"})\n// after\nauthUserAdd({\"user\": \"alice\", \"password\": \"s3cret\"})","handlingStrategy":"validation","validationCode":"for _, f := range []string{\"user\", \"password\"} {\n    if v, ok := params[f].(string); !ok || v == \"\" { return fmt.Errorf(\"field %s must be a non-empty string\", f) }\n}","typeGuard":"func nonEmptyString(p map[string]json.RawMessage, key string) bool {\n    var s string\n    return json.Unmarshal(p[key], &s) == nil && s != \"\"\n}","tryCatchPattern":"if err := authUserAdd(params); err != nil {\n    var codeErr struct{ Code string }\n    if strings.HasPrefix(err.Error(), \"ETCD_\") && strings.HasSuffix(err.Error(), \"_REQUIRED\") {\n        field := strings.ToLower(strings.TrimSuffix(strings.TrimPrefix(err.Error(), \"ETCD_\"), \"_REQUIRED\"))\n        return fmt.Errorf(\"missing required field: %s\", field)\n    }\n}","preventionTips":["Build auth RPC payloads from a typed struct so missing fields fail at compile time","Never default required auth fields to empty string","Unit-test each auth method's payload schema"],"tags":["etcd","validation","missing-parameter"],"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"}