From 600d905ebb051e07d6eccc45d817bf4b6f72a3d5 Mon Sep 17 00:00:00 2001 From: vominh1919 Date: Tue, 21 Apr 2026 10:26:04 +0700 Subject: [PATCH] fix: log errors instead of silently swallowing exceptions in gateway config loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three bare 'except Exception: pass' blocks in gateway/run.py masked real errors like yaml.YAMLError, PermissionError, and ImportError. Users with malformed config.yaml or missing modules got zero feedback. - Config YAML settings loading: log warning with exception details - IPv4 preference application: log warning with exception details - Config validation (print_config_warnings): log warning with exception details All three still preserve the non-fatal behavior — the gateway continues running — but now operators can see what went wrong in the logs. --- gateway/run.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/gateway/run.py b/gateway/run.py index ebaa0447b..2204e34b7 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -205,8 +205,10 @@ if _config_path.exists(): _redact = _security_cfg.get("redact_secrets") if _redact is not None: os.environ["HERMES_REDACT_SECRETS"] = str(_redact).lower() - except Exception: - pass # Non-fatal; gateway can still run with .env values + except Exception as e: + logging.getLogger(__name__).warning( + "Failed to apply config.yaml settings to environment: %s", e + ) # Apply IPv4 preference if configured (before any HTTP clients are created). try: @@ -214,15 +216,19 @@ try: _network_cfg = (_cfg if '_cfg' in dir() else {}).get("network", {}) if isinstance(_network_cfg, dict) and _network_cfg.get("force_ipv4"): apply_ipv4_preference(force=True) -except Exception: - pass +except Exception as e: + logging.getLogger(__name__).warning( + "Failed to apply IPv4 preference: %s", e + ) # Validate config structure early — log warnings so gateway operators see problems try: from hermes_cli.config import print_config_warnings print_config_warnings() -except Exception: - pass +except Exception as e: + logging.getLogger(__name__).warning( + "Failed to validate config.yaml: %s", e + ) # Gateway runs in quiet mode - suppress debug output and use cwd directly (no temp dirs) os.environ["HERMES_QUIET"] = "1"