Skip to content

Commit 8158db8

Browse files
committed
Give friendlier errors on password-file failures
instead of backtraces. This is more in line with other init errors such as bad DSNs.
1 parent 25493fe commit 8158db8

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Bug Fixes
1111
* Improve missing ssh-extras message.
1212
* Fix repeated control-r in traditional reverse isearch.
1313
* Fix spelling of `ssl-verify-server-cert` option.
14+
* Friendlier errors on password-file failures.
1415

1516

1617
Internal

mycli/main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@
7575
DEFAULT_HEIGHT = 25
7676

7777

78-
class PasswordFileError(Exception):
79-
"""Base exception for errors related to reading password files."""
80-
81-
8278
class MyCli:
8379
default_prompt = "\\t \\u@\\h:\\d> "
8480
default_prompt_splitln = "\\u@\\h\\n(\\t):\\d>"
@@ -561,13 +557,17 @@ def get_password_from_file(self, password_file: str) -> str:
561557
password = fp.readline().strip()
562558
return password
563559
except FileNotFoundError:
564-
raise PasswordFileError(f"Password file '{password_file}' not found") from None
560+
click.secho(f"Password file '{password_file}' not found", err=True, fg="red")
561+
sys.exit(1)
565562
except PermissionError:
566-
raise PasswordFileError(f"Permission denied reading password file '{password_file}'") from None
563+
click.secho(f"Permission denied reading password file '{password_file}'", err=True, fg="red")
564+
sys.exit(1)
567565
except IsADirectoryError:
568-
raise PasswordFileError(f"Path '{password_file}' is a directory, not a file") from None
566+
click.secho(f"Path '{password_file}' is a directory, not a file", err=True, fg="red")
567+
sys.exit(1)
569568
except Exception as e:
570-
raise PasswordFileError(f"Error reading password file '{password_file}': {str(e)}") from None
569+
click.secho(f"Error reading password file '{password_file}': {str(e)}", err=True, fg="red")
570+
sys.exit(1)
571571

572572
def handle_editor_command(self, text: str) -> str:
573573
r"""Editor command is any query that is prefixed or suffixed by a '\e'.

0 commit comments

Comments
 (0)