Skip to content

fix(runtime): readable config error when TELEGRAM_API_ID/HASH are missing - #312

Merged
chigwell merged 1 commit into
chigwell:mainfrom
axisrow:ao/telegram-mcp-5/fix-300-api-id-error
Oct 16, 2026
Merged

chigwell merged 1 commit into
chigwell:mainfrom
axisrow:ao/telegram-mcp-5/fix-300-api-id-error

Conversation

@axisrow

@axisrow axisrow commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Before

Starting the server without TELEGRAM_API_ID dies with a raw traceback that never mentions what is actually missing:

$ uv run main.py
Traceback (most recent call last):
  File "main.py", line 14, in <module>
    from telegram_mcp import runtime as _runtime
  ...
  File "telegram_mcp/runtime.py", line 153, in <module>
    TELEGRAM_API_ID = int(os.getenv("TELEGRAM_API_ID"))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

A non-numeric value fails the same way:

TypeError: int() argument must be... — for TELEGRAM_API_ID="1a2b": ValueError: invalid literal for int() with base 10: '1a2b'

The sibling entrypoints (migrate_session.py, session_string_generator.py) already print a readable message; only the server crashes.

After

Same startup now exits with a config error that names the variables and what to do, in the same style as the siblings:

$ uv run main.py
Error: TELEGRAM_API_ID and TELEGRAM_API_HASH must be set. Create an .env file with your credentials from https://my.telegram.org/apps

A malformed value gets its own message instead of a ValueError:

Error: TELEGRAM_API_ID must be an integer

What changed

telegram_mcp/runtime.py: the module-level int(os.getenv("TELEGRAM_API_ID")) is replaced with _require_api_credentials(), which validates presence, non-emptiness, and integer format before use and exits with the messages above. No behavior change when credentials are set correctly.

Tests

Fixes #300

🤖 Generated with Claude Code

…sing

Starting the server without TELEGRAM_API_ID crashed with a raw TypeError
from int(None) at import time. Validate both credentials (and the integer
format) before use and exit with the same message style as the migrator
and the session string generator, including a pointer to
https://my.telegram.org/apps.

Fixes chigwell#300

Co-Authored-By: Claude Code <[email protected]>
@chigwell
chigwell merged commit cd8b7ce into chigwell:main Oct 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

missing TELEGRAM_API_ID crashes with a raw TypeError on import

2 participants