fix: guard GUILD_ID env var cast against missing/invalid value (#26) #60
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
ai-working
bug
enhancement
feature
in-queue
performance
security
tech-debt
todo
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#60
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-discord-26"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Guards all three call sites of
int(os.environ.get('GUILD_ID'))againstNone/empty values by checking the env var before casting.Changes
cogs/gameplay.py(live_scorecard task loop): Addedguild_id = os.environ.get('GUILD_ID')+ early return withlogger.errorif unset, beforeself.bot.get_guild(int(guild_id))helpers/discord_utils.py:104: Same guard pattern insend_to_channel()discord_utils.py:104: Same fix in the top-level duplicateWhat was fixed
int(os.environ.get('GUILD_ID'))→int(None)raisesTypeErrorwhenGUILD_IDis unset. Inlive_scorecardthis was caught by the outerexcept Exceptionand logged, but masked the real problem. Insend_to_channel()it would crash callers without the protection.Notes
The linter hook (ruff) reformatted
cogs/gameplay.pywhen I made my edit. The functional GUILD_ID guard is in thelive_scorecardmethod (~line 128). The reformatting changes are purely cosmetic (quote style, import splitting, line wrapping) and do not affect behavior.Other observations
discord_utils.pyis a known dead duplicate (issue #34) — no production code imports it directlycogs/gameplay_legacy.pyhas the sameint(os.environ.get('GUILD_ID'))pattern at lines 48, 108, 112, 116 — not fixed here as it's legacy code, but worth notingCheck for None/empty before calling int() on os.environ.get('GUILD_ID') in all three call sites. Prevents TypeError crashing the live scoreboard task loop and send_to_channel() when GUILD_ID is unset. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>AI Code Review
Files Reviewed
cogs/gameplay.py(modified — ruff reformat + functional fix inlive_scorecard)helpers/discord_utils.py(modified — ruff reformat + functional fix insend_to_channel)discord_utils.py(modified — identical changes as helpers/discord_utils.py)Findings
Correctness
if not guild_id:correctly handles bothNone(env var unset) and""(env var set to empty string) before callingint(guild_id). This is the right pattern.int(guild_id)could still raiseValueErrorifGUILD_IDis set to a non-numeric string, but that is a deployment misconfiguration, not a runtime condition — appropriate not to guard against per project conventions. Inlive_scorecardit would be caught by the outerexcept Exception; insend_to_channelit would propagate to callers, which is acceptable.Security
Style & Conventions
Suggestions
cogs/gameplay_legacy.pystill has the same unguarded pattern at lines 48, 108, 112, 116. Since it's legacy code not in the active code path, this doesn't block merging — but tracking it in an issue would be worthwhile if not already done.Verdict: APPROVED
Clean, correct, minimal-scope fix. The guard pattern is applied consistently across all three call sites, addresses the root TypeError, and follows project conventions. Ruff reformatting is acceptable collateral.
Automated review by Claude PR Reviewer
7457cab110toc1a81b7bb9Pull request closed