From ec568eb44f7d09db9b9546f8a1555716fc3200ec Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Sat, 17 Jan 2026 15:14:39 -0500 Subject: [PATCH] graceful failure for --list-ssh-config If ~/.ssh/config is nontrivial, Paramiko can easily fail to parse it. Catch the failure and exit informatively rather than with a backtrace. --- changelog.md | 2 ++ mycli/main.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 3a4a7451..84545e80 100644 --- a/changelog.md +++ b/changelog.md @@ -5,9 +5,11 @@ Features -------- * Allow history file location to be configured. + Bug Fixes -------- * Respect `--logfile` when using `--execute` or standard input at the shell CLI. +* Gracefully catch Paramiko parsing errors on `--list-ssh-config`. 1.44.2 (2026/01/13) diff --git a/mycli/main.py b/mycli/main.py index 0b240c73..a785146f 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -1644,12 +1644,17 @@ def cli( sys.exit(0) if list_ssh_config: ssh_config = read_ssh_config(ssh_config_path) - for host in ssh_config.get_hostnames(): + try: + host_entries = ssh_config.get_hostnames() + except KeyError: + click.secho('Error reading ssh config', err=True, fg="red") + sys.exit(1) + for host_entry in host_entries: if verbose: - host_config = ssh_config.lookup(host) - click.secho(f"{host} : {host_config.get('hostname')}") + host_config = ssh_config.lookup(host_entry) + click.secho(f"{host_entry} : {host_config.get('hostname')}") else: - click.secho(host) + click.secho(host_entry) sys.exit(0) # Choose which ever one has a valid value. database = dbname or database