From 7d09133ab2b23ba908bc35cf476786471d298160 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Sat, 16 Aug 2025 07:12:02 -0400 Subject: [PATCH] Give friendlier errors on password-file failures instead of backtraces. This is more in line with other init errors such as bad DSNs. --- changelog.md | 1 + mycli/main.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index e631de04..841ee9c2 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,7 @@ Bug Fixes * Fix spelling of `ssl-verify-server-cert` option. * Improve handling of `ssl-verify-server-cert` False values. * Guard against missing contributors file on startup. +* Friendlier errors on password-file failures. Internal diff --git a/mycli/main.py b/mycli/main.py index 7094029f..7e4ee7f5 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -75,10 +75,6 @@ DEFAULT_HEIGHT = 25 -class PasswordFileError(Exception): - """Base exception for errors related to reading password files.""" - - class MyCli: default_prompt = "\\t \\u@\\h:\\d> " default_prompt_splitln = "\\u@\\h\\n(\\t):\\d>" @@ -561,13 +557,17 @@ def get_password_from_file(self, password_file: str) -> str: password = fp.readline().strip() return password except FileNotFoundError: - raise PasswordFileError(f"Password file '{password_file}' not found") from None + click.secho(f"Password file '{password_file}' not found", err=True, fg="red") + sys.exit(1) except PermissionError: - raise PasswordFileError(f"Permission denied reading password file '{password_file}'") from None + click.secho(f"Permission denied reading password file '{password_file}'", err=True, fg="red") + sys.exit(1) except IsADirectoryError: - raise PasswordFileError(f"Path '{password_file}' is a directory, not a file") from None + click.secho(f"Path '{password_file}' is a directory, not a file", err=True, fg="red") + sys.exit(1) except Exception as e: - raise PasswordFileError(f"Error reading password file '{password_file}': {str(e)}") from None + click.secho(f"Error reading password file '{password_file}': {str(e)}", err=True, fg="red") + sys.exit(1) def handle_editor_command(self, text: str) -> str: r"""Editor command is any query that is prefixed or suffixed by a '\e'.