{"record":{"id":"5529d3046d3a4aed","repo":"kovidgoyal/kitty","slug":"could-not-decode-window-system-key-q","errorCode":null,"errorMessage":"Could not decode window system key: {q}","messagePattern":"Could not decode window system key: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"kitty/rc/send_text.py","lineNumber":217,"sourceCode":"                yield from src\n\n        return chain()\n\n    def response_from_kitty(self, boss: Boss, window: Window | None, payload_get: PayloadGetType) -> ResponseType:\n        sid = payload_get('session_id', '')\n        windows = self.windows_for_payload(boss, window, payload_get, window_match_name='match')\n        pdata: str = payload_get('data')\n        encoding, _, q = pdata.partition(':')\n        session = ''\n        if encoding == 'text':\n            data: bytes | WindowSystemKeyEvent = q.encode('utf-8')\n        elif encoding == 'base64':\n            data = base64.standard_b64decode(q)\n        elif encoding == 'kitty-key':\n            bdata = base64.standard_b64decode(q)\n            candidate = decode_key_event_as_window_system_key(bdata.decode('ascii'))\n            if candidate is None:\n                raise ValueError(f'Could not decode window system key: {q}')\n            data = candidate\n        elif encoding == 'session':\n            session = q\n        else:\n            raise TypeError(f'Invalid encoding for send-text data: {encoding}')\n        exclude_active = payload_get('exclude_active')\n        actual_windows = (w for w in windows if w is not None and (not exclude_active or w is not boss.active_window))\n\n        def create_or_update_session() -> Session:\n            s = sessions_map.setdefault(sid, Session(sid))\n            return s\n\n        if session == 'end':\n            s = create_or_update_session()\n            for w in actual_windows:\n                w.screen.render_unfocused_cursor = False\n                s.window_ids.discard(w.id)\n            ClearSession(sid)()","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/rc/send_text.py#L199-L235","documentation":"send-text with encoding='kitty-key' base64-decodes the payload and tries to interpret it as a window-system key event. If decode_key_event_as_window_system_key returns None the text cannot be mapped to a key and ValueError is raised.","triggerScenarios":"Calling kitten @send-text --encoding kitty-key with a base64 string that is not a valid encoded kitty key event (malformed or wrong key name).","commonSituations":"Hand-crafting kitty-key payloads, or sending key text produced for a different kitty version/key encoding scheme.","solutions":["Regenerate the payload using kitty's own key encoding (e.g. kitten @send-text with a recorded key event)","Validate the base64 string decodes to ASCII before sending","Fall back to encoding='text' with base64 for plain text"],"exampleFix":"# before\nkitten @send-text --encoding kitty-key <bad-b64>\n# after\nkitten @send-text --encoding base64 \"plain text\"","handlingStrategy":"validation","validationCode":"import base64\nfrom kitty.key_encoding import decode_key_event_as_window_system_key\nb = base64.standard_b64decode(payload)\nassert decode_key_event_as_window_system_key(b.decode('ascii')) is not None","typeGuard":null,"tryCatchPattern":"except ValueError as e: print('bad kitty-key payload', e); fallback to base64 text encoding","preventionTips":["Generate kitty-key payloads with kitty's own encoders","Pre-validate base64+ASCII round-trip"],"tags":["kitty","send-text","encoding"],"backgroundTag":"payload-decode-failed","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}