fix(followups): F2 - Python entry points report an unreadable env file in one line

A .mam.env that exists but cannot be read or decoded stopped the Python
entry points with an EnvFileError traceback, while the wrapper printed one
`ERROR:` line and exited 1 (PR #43 review claude S1). The mains that load the
env file - publish_event, registry, job_subscriber, cli, bench, heartbeat and
remote - now call mqtt_common.load_env_or_report(), which prints
`ERROR: <path>: cannot read (<exception type>)` and lets the main return 1.
No value or file content is printed. ensure_env_loaded() still raises: no
library function exits the process.

Test: every entry point, for a 000 file and an undecodable one, ends with
exactly that line and rc 1 and creates nothing (14 cases; all 14 fail at
0051fd6 with a traceback).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCGpJXhSZasJLU38ksDghe
This commit is contained in:
GodopuandClaude Opus 5.5 committed 2026-10-02 08:09:46 +09:00
1 parent 75936f11c6
commit 5edf913d22
9 files changed
+73 -9

No files matched your search

@@ -21,6 +21,7 @@ import hmac
import json
import logging
import os
import sys
import tempfile
import time
import uuid
@@ -110,9 +111,10 @@ def ensure_env_loaded(workspace_dir: Optional[str] = None) -> None:
"""Load the workspace env file exactly once per process (D6, issue #5 phase 1).
This used to run at import time. Importing a library must not mutate
``os.environ``, so every *process entry point* calls this instead:
``os.environ``, so every *process entry point* calls this instead -
``publish_event.main``, ``registry.main``, ``job_subscriber.main``,
``cli.main``, ``bench.main``, and reconcile.sh's embedded subscriber.
``cli.main``, ``bench.main``, ``heartbeat.main`` and ``remote.main``
through :func:`load_env_or_report`, and reconcile.sh's embedded subscriber.
Production semantics are unchanged because every production path passes
through one of those, and OS env still wins over the file
(see :func:`_parse_env_file`).
@@ -123,6 +125,20 @@ def ensure_env_loaded(workspace_dir: Optional[str] = None) -> None:
_env_loaded = True
_load_dotenv(workspace_dir)
def load_env_or_report() -> bool:
"""ensure_env_loaded() for a process entry point: an env file that exists
but cannot be read ends the process the way the wrapper does - one
`ERROR: <path>: cannot read (<exception type>)` line, no traceback, no
value - and the caller returns 1. False after printing; library code keeps
calling ensure_env_loaded() and never exits."""
try:
ensure_env_loaded()
except envfile.EnvFileError as e:
print(f"ERROR: {e}", file=sys.stderr)
return False
return True
# --------------------------------------------------------------------------
# Constants
# --------------------------------------------------------------------------