{"record":{"id":"3e1a12cda7eb5308","repo":"gastownhall/beads","slug":"got-d-close-reasons-for-d-issue-ids-provide-exa","errorCode":null,"errorMessage":"got %d close reasons for %d issue IDs; provide exactly one shared reason or one reason per issue","messagePattern":"got (.+?) close reasons for (.+?) issue IDs; provide exactly one shared reason or one reason per issue","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/close.go","lineNumber":452,"sourceCode":"\n\tif fileReason, ok, err := resolveReasonFile(cmd, len(reasons) > 0); err != nil {\n\t\treturn nil, args, err\n\t} else if ok {\n\t\treasons = []string{fileReason}\n\t}\n\n\t// Desire-path: \"bd done <id> <message>\" treats last positional arg as reason\n\t// when no reason flag was explicitly provided (hq-pe8ce)\n\tif len(reasons) == 0 && cmd.CalledAs() == \"done\" && len(args) >= 2 {\n\t\treasons = []string{args[len(args)-1]}\n\t\targs = args[:len(args)-1]\n\t}\n\n\tif len(reasons) == 0 {\n\t\treasons = []string{\"Closed\"}\n\t}\n\tif len(reasons) > 1 && len(reasons) != len(args) {\n\t\treturn nil, args, fmt.Errorf(\"got %d close reasons for %d issue IDs; provide exactly one shared reason or one reason per issue\", len(reasons), len(args))\n\t}\n\treturn reasons, args, nil\n}\n\nfunc collectCloseReasonFlags(cmd *cobra.Command) ([]string, error) {\n\tif flag := cmd.Flags().Lookup(\"reason\"); flag != nil {\n\t\tif v, ok := flag.Value.(interface{ Values() []string }); ok {\n\t\t\tif reasons := nonEmptyCloseReasons(v.Values()); len(reasons) > 0 {\n\t\t\t\treturn reasons, nil\n\t\t\t}\n\t\t}\n\t}\n\n\tfor _, name := range []string{\"resolution\", \"message\", \"comment\"} {\n\t\treason, err := cmd.Flags().GetString(name)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/close.go#L434-L470","documentation":"resolveCloseReasons validates that when multiple `--reason` flags are supplied to `bd close`, their count must either be 1 (shared reason for all issues) or exactly equal to the number of issue ID arguments. If the counts mismatch, closing is refused to avoid ambiguous reason-to-issue mapping.","triggerScenarios":"Calling `bd close` with N issue IDs and more than one --reason flag where the number of reasons != N, e.g. `bd close bd-1 bd-2 bd-3 --reason a --reason b`.","commonSituations":"Shell scripts building the reason list dynamically; users pasting a partial list of per-issue reasons; forgetting an issue ID in the argument list while providing full per-issue reasons.","solutions":["Supply exactly one --reason to apply it to all issues, or one --reason per issue ID so counts match.","Count reasons and IDs in your script before invoking bd close.","Alternatively use --reason-file with a single shared reason text."],"exampleFix":"// before\nbd close bd-1 bd-2 bd-3 --reason \"done\" --reason \"done\"\n// after\nbd close bd-1 bd-2 bd-3 --reason \"done\"","handlingStrategy":"validation","validationCode":"if [ $(printf '%s\\n' \"$@\" | grep -c -- '--reason') -gt 1 ]; then\n  # ensure reasons count == issue ids count, else use a single --reason\nfi","typeGuard":"func reasonsMatchIDs(reasons, ids []string) bool {\n\treturn len(reasons) <= 1 || len(reasons) == len(ids)\n}","tryCatchPattern":"reasons, args, err := resolveCloseReasons(cmd, args)\nif err != nil && strings.Contains(err.Error(), \"close reasons for\") {\n\t// fall back to a single shared reason and retry\n}","preventionTips":["Always use a single --reason in scripts unless intentionally doing per-issue reasons","Count flags programmatically before invoking bd close","Prefer --reason-file for shared multi-line reasons"],"tags":["cli","validation","argument-count"],"backgroundTag":"argument-count-mismatch","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}