{"record":{"id":"a8dd3d419f44e4d4","repo":"t8y2/dbx","slug":"etcd-defrag-target-required","errorCode":"ETCD_DEFRAG_TARGET_REQUIRED","errorMessage":"ETCD_DEFRAG_TARGET_REQUIRED: at least one endpoint is required","messagePattern":"ETCD_DEFRAG_TARGET_REQUIRED: at least one endpoint is required","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd-go/maintenance.go","lineNumber":68,"sourceCode":"\t\treturn nil, err\n\t}\n\treturn map[string]any{\"revision\": longString(revision)}, nil\n}\n\nfunc (s *etcdSession) defrag(params map[string]json.RawMessage) (any, error) {\n\tvar targets []string\n\tif raw := params[\"endpoints\"]; len(raw) > 0 && string(raw) != \"null\" {\n\t\tvar list []string\n\t\tif jsonUnmarshal(raw, &list) == nil {\n\t\t\tfor _, endpoint := range list {\n\t\t\t\tif endpoint != \"\" && !containsString(targets, endpoint) {\n\t\t\t\t\ttargets = append(targets, endpoint)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif len(targets) == 0 {\n\t\treturn nil, errors.New(\"ETCD_DEFRAG_TARGET_REQUIRED: at least one endpoint is required\")\n\t}\n\tclient, err := s.activeClient()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tmembers := []map[string]any{}\n\tremaining := targets\n\tfor len(remaining) > 0 {\n\t\tendpoint, err := nextDefragEndpoint(client, remaining)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tstarted := time.Now()\n\t\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeoutSeconds*time.Second)\n\t\t_, defragErr := client.Maintenance.Defragment(ctx, endpoint)\n\t\tcancel()\n\t\tdurationMs := time.Since(started).Milliseconds()","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd-go/maintenance.go#L50-L86","documentation":"defrag collects the target endpoints from params (top-level endpoints and/or per-target entries); if after filtering nothing valid remains, it refuses to run and returns ETCD_DEFRAG_TARGET_REQUIRED: at least one endpoint is required. Defragmenting is a per-endpoint maintenance operation, so running it cluster-wide with no explicit targets would be ambiguous and dangerous; the library requires at least one explicit target.","triggerScenarios":"Calling defrag (via handle) with no \"endpoints\" array, an empty array, or entries that all fail the endpoint filter (e.g. blank strings), so len(targets)==0 at maintenance.go:68. TestDefragRequiresErrors... TestDefragRequiresEndpoints asserts this behavior.","commonSituations":"Automation that builds the defrag request from config where the endpoints list is empty or unset; YAML/JSON typo (\"endpoint\" vs \"endpoints\"); all candidate endpoints filtered out because of whitespace or malformed URLs in configuration.","solutions":["Pass a non-empty \"endpoints\" array (e.g. [\"http://10.0.0.1:2379\",\"http://10.0.0.2:2379\"]) in the defrag params.","Fix configuration so the endpoints list is populated and free of blank/invalid entries.","Validate endpoint list non-empty (and each entry parses as a URL) before dispatching defrag.","If you intend all members, explicitly enumerate them rather than relying on an implicit default."],"exampleFix":"// before\nagent.call(\"defrag\", {}) // no targets\n\n// after\nagent.call(\"defrag\", {\"endpoints\": [\"http://10.0.0.1:2379\", \"http://10.0.0.2:2379\"]})","handlingStrategy":"validation","validationCode":"func validateDefragEndpoints(eps []string) error {\n    if len(eps) == 0 {\n        return errors.New(\"defrag requires at least one endpoint\")\n    }\n    for _, e := range eps {\n        if strings.TrimSpace(e) == \"\" {\n            return fmt.Errorf(\"invalid endpoint %q\", e)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the 'endpoints' array is populated and non-empty in config.","Trim and URL-validate each endpoint before building the request.","Explicitly list all members if you intend a cluster-wide defrag."],"tags":["etcd","defrag","validation","maintenance","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"}