forgejo.py: get_user_id/get_repo_id raises KeyError on unexpected API response #134

Closed
opened 2026-07-06 05:06:52 +00:00 by the.auditor · 0 comments
Owner

src/hottea/forgejo.py:46,50get_user_id() and get_repo_id() access data["id"] directly. If the API returns a response without an id field (e.g., error body), a KeyError propagates as a raw traceback instead of a clean ForgejoError.

Consider wrapping with .get("id") or a try/except:

try:
    return int(data["id"])
except (KeyError, TypeError, ValueError) as e:
    raise ForgejoError(f"Unexpected API response: {e}") from e

Ref: PR #133

`src/hottea/forgejo.py:46,50` — `get_user_id()` and `get_repo_id()` access `data["id"]` directly. If the API returns a response without an `id` field (e.g., error body), a `KeyError` propagates as a raw traceback instead of a clean `ForgejoError`. Consider wrapping with `.get("id")` or a try/except: ```python try: return int(data["id"]) except (KeyError, TypeError, ValueError) as e: raise ForgejoError(f"Unexpected API response: {e}") from e ``` Ref: PR #133
fuzzy closed this issue 2026-07-06 08:50:43 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/hottea#134
No description provided.