{"record":{"id":"942facb4ac7e7d53","repo":"kovidgoyal/kitty","slug":"must-specify-exactly-s-argument-s-for-s","errorCode":null,"errorMessage":"Must specify exactly %s argument(s) for %s","messagePattern":"Must specify exactly (.+?) argument\\(s\\) for (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kitty/rc/base.py","lineNumber":230,"sourceCode":"    def args_count(self) -> int | None:\n        if not self.spec:\n            return 0\n        return self.count\n\n    def as_go_completion_code(self, go_name: str) -> Iterator[str]:\n        c = self.args_count\n        if c is not None:\n            yield f'{go_name}.StopCompletingAtArg = {c}'\n        if self.completion:\n            yield from self.completion.as_go_code(go_name + '.ArgCompleter', ' = ')\n\n    def as_go_code(self, cmd_name: str, field_types: dict[str, str], handled_fields: set[str]) -> Iterator[str]:\n        c = self.args_count\n        if c == 0:\n            yield f'if len(args) != 0 {{ return fmt.Errorf(\"%s\", \"Unknown extra argument(s) supplied to {cmd_name}\") }}'\n            return\n        if c is not None:\n            yield f'if len(args) != {c} {{ return fmt.Errorf(\"%s\", \"Must specify exactly {c} argument(s) for {cmd_name}\") }}'\n        if self.value_if_unspecified:\n            yield 'if len(args) == 0 {'\n            for x in self.value_if_unspecified:\n                yield f'args = append(args, \"{x}\")'\n            yield '}'\n        if self.minimum_count > -1:\n            if self.minimum_count == 1:\n                yield f'if len(args) < {self.minimum_count} {{ return fmt.Errorf(\"%s\", \"Must specify at least one argument to {cmd_name}\") }}'\n            else:\n                yield f'if len(args) < {self.minimum_count} {{ return fmt.Errorf(\"%s\", \"Must specify at least {self.minimum_count} arguments to {cmd_name}\") }}'\n        if self.args_choices:\n            achoices = tuple(self.args_choices())\n            yield 'achoices := map[string]bool{' + ' '.join(f'\"{x}\":true,' for x in achoices) + '}'\n            yield 'for _, a := range args {'\n            yield 'if !achoices[a] { return fmt.Errorf(\"Not a valid choice: %s. Allowed values are: %s\", a, \"' + ', '.join(achoices) + '\") }'\n            yield '}'\n        if self.json_field:\n            jf = self.json_field","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/rc/base.py#L212-L248","documentation":"Generated Go validation for RC commands with a fixed positive args_count: the handler checks len(args) against the required count and rejects mismatches, telling you exactly how many arguments the command needs.","triggerScenarios":"Calling a remote control command with too few or too many positional args — e.g. a command requiring exactly 2 args given 1 or 3; happens via kitten @ CLI, the remote control socket JSON payload, or scripts building arg arrays dynamically.","commonSituations":"Unquoted shell words splitting/joining args incorrectly; commands whose arg count changed across kitty versions; programmatic RC payloads with hardcoded arg arrays drifting from the schema; empty string args being dropped.","solutions":["Supply exactly the number of positional args stated in the error message","Inspect kitty @ <cmd> --help for the argument list and order","In scripts, quote each argument explicitly and assert len(args) == expected before sending","Pin/align kitty versions between client and server so arg schemas match"],"exampleFix":"# before\nkitten @ send-text --match-tab title:mytab \"hello\"\n# (command expected exactly N positional args, got fewer)\n\n# after\n# pass each required positional argument, properly quoted:\nkitten @ send-text hello","handlingStrategy":"validation","validationCode":"if len(args) != cmd.ArgsCount {\n    return fmt.Errorf(\"%s needs exactly %d args, got %d\", cmd.Name, cmd.ArgsCount, len(args))\n}","typeGuard":"func hasExactArgs(args []string, n int) bool { return len(args) == n }","tryCatchPattern":"if err := runRCCommand(cmd, args); err != nil {\n    if strings.Contains(err.Error(), \"Must specify exactly\") {\n        return fmt.Errorf(\"%w — check kitty @ %s --help\", err, cmd.Name)\n    }\n    return err\n}","preventionTips":["Quote every argument in shell scripts to preserve counts","Check --help output for the installed kitty version","Validate arg arrays before writing to the RC socket"],"tags":["kitty","remote-control","arguments","arity","validation"],"backgroundTag":"wrong-argument-count","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}