{"record":{"id":"8eaf8e8a4945e005","repo":"kovidgoyal/kitty","slug":"the-value-x-is-not-a-known-choice","errorCode":null,"errorMessage":"The value {x} is not a known choice","messagePattern":"The value (.+?) is not a known choice","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"kitty/conf/utils.py","lineNumber":142,"sourceCode":"\n\ndef python_string(text: str) -> str:\n    from ast import literal_eval\n\n    text = (text[:-1] + \"\\\\'\") if text.endswith(\"'\") else text\n    ans: str = literal_eval(\"'''\" + text.replace(\"'''\", \"'\\\\''\") + \"'''\")\n    return ans\n\n\nclass Choice:\n    def __init__(self, choices: Sequence[str]):\n        self.defval = choices[0]\n        self.all_choices = frozenset(choices)\n\n    def __call__(self, x: str) -> str:\n        x = x.lower()\n        if x not in self.all_choices:\n            raise ValueError(f'The value {x} is not a known choice')\n        return x\n\n\ndef choices(*choices: str) -> Choice:\n    return Choice(choices)\n\n\nclass CurrentlyParsing:\n    __slots__ = 'line', 'number', 'file'\n\n    def __init__(self, line: str = '', number: int = -1, file: str = ''):\n        self.line = line\n        self.number = number\n        self.file = file\n\n    def __copy__(self) -> 'CurrentlyParsing':\n        return CurrentlyParsing(self.line, self.number, self.file)\n","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/conf/utils.py#L124-L160","documentation":"Choice.__call__ (from choices()) lowercases the input and raises ValueError if it is not among the declared choices — the standard parser for enum-like kitty config options.","triggerScenarios":"Setting a choice-based config option (e.g. a strategy/mode enum) to a value not in the parser's choice set; note comparison is case-insensitive after lowercasing.","commonSituations":"Misspelled enum values in kitty.conf, or values valid only in newer/older kitty versions.","solutions":["Check the option's documented choices and fix the spelling","Upgrade/downgrade kitty to match the available choices","Remember matching is case-insensitive, so case is not the issue"],"exampleFix":"# before\nbackground_tint none-x\n# after\nbackground_tint no","handlingStrategy":"type-guard","validationCode":"allowed = set(choice_parser.all_choices)\nif value.lower() not in allowed:\n    value = choice_parser.defval","typeGuard":"def is_valid_choice(choice: Choice, x: str) -> bool:\n    return x.lower() in choice.all_choices","tryCatchPattern":"try:\n    v = choice_parser(x)\nexcept ValueError:\n    v = choice_parser.defval","preventionTips":["Populate UI dropdowns from the parser's all_choices","Lowercase user input before validating against choices"],"tags":["kitty","config","enum","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}