{"record":{"id":"a6d0547d97cd178e","repo":"kovidgoyal/kitty","slug":"invalid-base64-encoded-data-from-terminal-with-err","errorCode":null,"errorMessage":"Invalid base64 encoded data from terminal with error: %w","messagePattern":"Invalid base64 encoded data from terminal with error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/clipboard/legacy.go","lineNumber":198,"sourceCode":"\tvar clipboard_contents []byte\n\n\tlp.OnEscapeCode = func(etype loop.EscapeCodeType, data []byte) (err error) {\n\t\tswitch etype {\n\t\tcase loop.DCS:\n\t\t\tif strings.HasPrefix(utils.UnsafeBytesToString(data), \"1+r\") {\n\t\t\t\tlp.Quit(0)\n\t\t\t}\n\t\tcase loop.OSC:\n\t\t\tq := utils.UnsafeBytesToString(data)\n\t\t\tif strings.HasPrefix(q, \"52;\") {\n\t\t\t\tparts := strings.SplitN(q, \";\", 3)\n\t\t\t\tif len(parts) < 3 {\n\t\t\t\t\tlp.Quit(0)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tdata, err := base64.StdEncoding.DecodeString(parts[2])\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"Invalid base64 encoded data from terminal with error: %w\", err)\n\t\t\t\t}\n\t\t\t\tclipboard_contents = data\n\t\t\t\tlp.Quit(0)\n\t\t\t}\n\t\t}\n\t\treturn\n\t}\n\n\tesc_count := 0\n\tlp.OnKeyEvent = func(event *loop.KeyEvent) error {\n\t\tif event.MatchesPressOrRepeat(\"ctrl+c\") || event.MatchesPressOrRepeat(\"esc\") {\n\t\t\tif transmitting {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tevent.Handled = true\n\t\t\tesc_count++\n\t\t\tif esc_count < 2 {\n\t\t\t\tkey := \"Esc\"","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/clipboard/legacy.go#L180-L216","documentation":"When reading the clipboard from the terminal, the kitten sends an OSC 52-style query and expects the reply base64-encoded. If the returned data cannot be base64-decoded, this error is raised. The terminal sent garbage instead of valid base64.","triggerScenarios":"Asking the terminal for clipboard contents (get mode) where the reply's third part fails base64.StdEncoding.DecodeString — e.g. corrupted or empty payload, or another program answered the query.","commonSituations":"Running inside tmux/screen that mangles DCS/OSC replies, shell prompt escape sequences interfering with terminal queries, non-kitty terminals with partial OSC 52 support.","solutions":["Run outside tmux/screen or enable proper escape-sequence passthrough","Update kitty and the terminal emulator","Check that shell integration/prompt isn't injecting escape codes that answer queries"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if _, err := base64.StdEncoding.DecodeString(parts[2]); err != nil {\n\treturn errors.New(\"terminal clipboard reply not base64; run inside kitty without multiplexer mangling\")\n}","typeGuard":null,"tryCatchPattern":"data, err := base64.StdEncoding.DecodeString(s)\nif err != nil { return nil, fmt.Errorf(\"bad clipboard payload: %w\", err) }","preventionTips":["Run clipboard get directly in kitty, not through tmux/screen","Keep shell prompt escape codes from answering terminal queries"],"tags":["kitty","clipboard","base64","osc52"],"backgroundTag":"terminal-query-response-malformed","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}