From 8afea7f8b5e118276d32eb11f33d53f2992ebcaf Mon Sep 17 00:00:00 2001 From: laggykiller Date: Thu, 8 Feb 2024 09:41:56 +0800 Subject: [PATCH] Fix cli crash if no credential files given --- src/sticker_convert/cli.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sticker_convert/cli.py b/src/sticker_convert/cli.py index b1d9aa6..1a831ee 100755 --- a/src/sticker_convert/cli.py +++ b/src/sticker_convert/cli.py @@ -375,10 +375,14 @@ def get_opt_comp(self, args: Namespace) -> CompOption: def get_opt_cred(self, args: Namespace) -> CredOption: creds_path = CONFIG_DIR / "creds.json" creds = {} - try: - creds = JsonManager.load_json(creds_path) - except JSONDecodeError: - self.cb.msg("Warning: creds.json content is corrupted") + if creds_path.is_file(): + try: + creds = JsonManager.load_json(creds_path) + except JSONDecodeError: + self.cb.msg("Warning: creds.json content is corrupted") + creds = {} + else: + creds = {} if creds: self.cb.msg("Loaded credentials from creds.json")