From 2c6e446256a890e61690010f85d64d89f6ba2531 Mon Sep 17 00:00:00 2001 From: Quratulain-bilal Date: Wed, 29 Jul 2026 12:19:34 +0500 Subject: [PATCH 1/2] fix: add JSON error handling to auth config loader Wrap json.loads() in load_auth_config() with try/except to catch JSONDecodeError and raise a clean ValueError with a descriptive message, matching the convention used for all other validation failures in the same function. --- src/specify_cli/authentication/config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/specify_cli/authentication/config.py b/src/specify_cli/authentication/config.py index 829940d6f7..94429f3c9f 100644 --- a/src/specify_cli/authentication/config.py +++ b/src/specify_cli/authentication/config.py @@ -102,7 +102,10 @@ def load_auth_config( except OSError: pass # stat failed — skip permission check - raw = json.loads(config_path.read_text(encoding="utf-8")) + try: + raw = json.loads(config_path.read_text(encoding="utf-8")) + except json.JSONDecodeError as exc: + raise ValueError(f"{config_path} contains invalid JSON: {exc}") from exc if not isinstance(raw, dict): raise ValueError(f"auth.json must be a JSON object, got {type(raw).__name__}") From e33235d9389dfeb0d60118c29f227bc37334760d Mon Sep 17 00:00:00 2001 From: Quratulain-bilal Date: Sat, 8 Aug 2026 02:47:38 +0500 Subject: [PATCH 2/2] fix: add JSON error handling to auth config loader Wrap json.loads() in load_auth_config() with try/except to catch malformed JSON and raise a clean ValueError with path context. Update test to expect ValueError instead of JSONDecodeError. --- tests/test_authentication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_authentication.py b/tests/test_authentication.py index 523b0c4f30..4f924ad20e 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -205,7 +205,7 @@ def test_multiple_entries(self, tmp_path): def test_invalid_json_raises(self, tmp_path): cfg = tmp_path / "auth.json" cfg.write_text("not json") - with pytest.raises(json.JSONDecodeError): + with pytest.raises(ValueError, match="invalid JSON"): load_auth_config(cfg) def test_not_object_raises(self, tmp_path):