{"record":{"id":"c392f6e02ede2452","repo":"t8y2/dbx","slug":"etcd-s-required","errorCode":"ETCD_%s_REQUIRED","errorMessage":"ETCD_%s_REQUIRED","messagePattern":"ETCD_(.+?)_REQUIRED","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd-go/kv.go","lineNumber":627,"sourceCode":"\tvar value int64\n\tif err := json.Unmarshal(raw, &value); err != nil {\n\t\treturn nil\n\t}\n\treturn &value\n}\n\nfunc requiredPositiveLong(params map[string]json.RawMessage, field string) (int64, error) {\n\tvalue := longOrNull(params, field)\n\tif value == nil || *value <= 0 {\n\t\treturn 0, fmt.Errorf(\"ETCD_INVALID_%s: a positive integer is required\", strings.ToUpper(field))\n\t}\n\treturn *value, nil\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":609,"sourceCodeEnd":631,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd-go/kv.go#L609-L631","documentation":"requiredString validates that a string request field is present and non-empty for auth operations. When the field is missing, null, or the empty string, it throws the typed error ETCD_<FIELD>_REQUIRED with the uppercased field name (e.g. ETCD_USER_REQUIRED). This is an input-validation guard so auth requests never reach etcd with blank identities.","triggerScenarios":"authUserAdd, authUserDelete, authUserChangePassword, authUserGrantRevokeRole, authRoleGet, or authRoleAdd called with params missing the required field (e.g. \"user\" or \"role\"), set to null, or set to \"\".","commonSituations":"Empty username/password from an unset environment variable interpolated into the request; trimming removed whitespace leaving \"\"; a form/CLI where the user skipped a prompt; refactored client passing wrong JSON key so the expected field is absent.","solutions":["Read the error code to identify the field (e.g. ETCD_USER_REQUIRED) and supply a non-empty string for it.","Validate inputs at the call boundary: reject empty/whitespace-only strings before calling.","Fix upstream config/env so the identity field is actually populated (check the env var or secret is set).","Verify the request uses the exact JSON field name the driver expects (case-sensitive); a renamed key looks like a missing field."],"exampleFix":"// before\n{\"user\": \"\"} // ETCD_USER_REQUIRED\n// after\n{\"user\": \"alice\", \"password\": \"s3cret\"}","handlingStrategy":"validation","validationCode":"func validateRequiredString(params map[string]json.RawMessage, fields ...string) error {\n\tfor _, f := range fields {\n\t\traw, ok := params[f]\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"field %s is required\", f)\n\t\t}\n\t\tvar s string\n\t\tif err := json.Unmarshal(raw, &s); err != nil || strings.TrimSpace(s) == \"\" {\n\t\t\treturn fmt.Errorf(\"field %s must be a non-empty string\", f)\n\t\t}\n\t}\n\treturn nil\n}\n// validateRequiredString(params, \"user\", \"password\") before authUserAdd","typeGuard":"func nonEmptyString(v any) (string, bool) {\n\ts, ok := v.(string)\n\treturn s, ok && s != \"\"\n}","tryCatchPattern":"err := driver.AuthUserAdd(params)\nif err != nil {\n\tvar typed interface{ Code() string }\n\tif errors.As(err, &typed) && strings.HasSuffix(typed.Code(), \"_REQUIRED\") {\n\t\tfield := strings.TrimSuffix(strings.TrimPrefix(typed.Code(), \"ETCD_\"), \"_REQUIRED\")\n\t\treturn fmt.Errorf(\"missing field %s: %w\", strings.ToLower(field), err)\n\t}\n\treturn err\n}","preventionTips":["Check environment variables / secrets for auth identities before constructing requests.","Use explicit request builders that refuse to serialize empty required fields.","Keep field names in a shared constants file to avoid case/key mismatches.","Reject whitespace-only strings, not just empty ones, during pre-validation."],"tags":["validation","etcd","auth","parameters"],"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"}