Skip to content
This repository was archived by the owner on Jul 16, 2026. It is now read-only.

fix(discord-bridge): guard import-time exit(1) behind __main__ check - #100

Open
jgluck96 wants to merge 1 commit into
mainfrom
fix/ci-discord-bridge-import-exit
Open

jgluck96 wants to merge 1 commit into
mainfrom
fix/ci-discord-bridge-import-exit

Conversation

@jgluck96

@jgluck96 jgluck96 commented Jun 4, 2026

Copy link
Copy Markdown

Summary

discord-bridge.py calls exit(1) at module level when DISCORD_BOT_TOKEN is not set. Any process that imports the module (test runner, type checker, or future skill that introspects the bridge) gets silently killed.

  • Guard the exit(1) behind if __name__ == "__main__": so imports are safe
  • Replace bare exit(1) with sys.exit(1) for explicitness

Test plan

  • Start discord-bridge with no token set → still exits with error message
  • Import discord-bridge in a test context → no longer exits the process

🤖 Generated with Claude Code

Unblocks CI for PRs that import discord-bridge.py in tests when
DISCORD_BOT_TOKEN is not set in the CI environment. The exit(1) at
module import time killed the entire test loop for any PR touching
the bridge, silently dropping approved PRs (#60, #62, #52).

The process should still exit when run directly (not imported), so
the guard uses __name__ == "__main__" — the standard Python idiom.

@bassilkhilo-ag2 bassilkhilo-ag2 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct guard. exit(1) at import time breaks any test or script that does import discord-bridge (or importlib load) without DISCORD_BOT_TOKEN set. Wrapping in if __name__ == '__main__' is the standard Python pattern for import-safe exit guards. sys.exit preferred over bare exit in scripts — same effect here since sys is already imported. Approved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants