{"record":{"id":"8df5bdc097bd7d7e","repo":"kovidgoyal/kitty","slug":"invalid-ssh-connection-data-w","errorCode":null,"errorMessage":"invalid --ssh-connection-data: %w","messagePattern":"invalid --ssh-connection-data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/remote_file/ssh.go","lineNumber":28,"sourceCode":"\t\"strings\"\n)\n\n// Must match kittens/remote_file/main.py is_ssh_kitten_sentinel\nconst is_ssh_kitten_sentinel = `!#*&$#($ssh-kitten)(##$`\n\ntype SSHConnectionData struct {\n\tBinary           string\n\tHostname         string\n\tPort             int\n\tIdentityFile     string\n\tIsSSHKitten      bool\n\tSSHKittenCmdline []string\n}\n\nfunc parse_conn_data(raw string) (*SSHConnectionData, error) {\n\tvar items []any\n\tif err := json.Unmarshal([]byte(raw), &items); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid --ssh-connection-data: %w\", err)\n\t}\n\tif len(items) < 2 {\n\t\treturn nil, fmt.Errorf(\"invalid --ssh-connection-data: need at least binary and hostname\")\n\t}\n\tfirst, _ := items[0].(string)\n\tans := &SSHConnectionData{}\n\tif first == is_ssh_kitten_sentinel {\n\t\t// Python: SSHConnectionData(sentinel, cli_data[-1], -1, identity_file=json.dumps(cli_data[1:]))\n\t\t// with the cmdline stripped of -t flags and its last two items.\n\t\tans.IsSSHKitten = true\n\t\tans.Hostname, _ = items[len(items)-1].(string)\n\t\tcmdline := make([]string, 0, len(items)-1)\n\t\tfor _, x := range items[1:] {\n\t\t\ts, _ := x.(string)\n\t\t\tif s != \"-t\" {\n\t\t\t\tcmdline = append(cmdline, s)\n\t\t\t}\n\t\t}","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/remote_file/ssh.go#L10-L46","documentation":"parse_conn_data JSON-decodes the --ssh-connection-data argument (a JSON array). This variant fires when json.Unmarshal fails, i.e. the argument is not valid JSON at all. It is called by handle_action and exercised by tests.","triggerScenarios":"Passing --ssh-connection-data with malformed JSON: missing brackets, trailing commas, single quotes, or shell-quoting corruption of the array.","commonSituations":"Hand-writing or shell-escaping the argument incorrectly when invoking the remote_file kitten manually instead of letting kitty construct it.","solutions":["Validate the argument with a JSON linter before passing it","Pass the array as proper JSON: [\"/usr/bin/ssh\",\"host\"]","Let kitty generate --ssh-connection-data rather than constructing it by hand","In tests, build the JSON with json.Marshal instead of string concatenation"],"exampleFix":"// before\n--ssh-connection-data '/usr/bin/ssh host'\n// after\n--ssh-connection-data '[\"/usr/bin/ssh\",\"host\"]'","handlingStrategy":"validation","validationCode":"var items []any\nif err := json.Unmarshal([]byte(raw), &items); err != nil { /* reject before calling */ }","typeGuard":"func isValidConnData(raw string) bool { var v []any; return json.Unmarshal([]byte(raw), &v) == nil }","tryCatchPattern":null,"preventionTips":["Always build the argument with json.Marshal","Shell-quote the whole argument as one word","Add unit tests for malformed input"],"tags":["json","parsing","cli-args","ssh"],"backgroundTag":"invalid-json-input","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}