From be392926339278b83316b08fbd1e0647c84779bd Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Sat, 28 Mar 2026 11:39:01 -0700 Subject: [PATCH] fix(cli): guard .strip() against None values from YAML config (#3552) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dict.get(key, default) only returns default when key is ABSENT. When YAML has 'key:' with no value, it parses as None — .get() returns None, then .strip() crashes with AttributeError. Use (x or '') pattern to handle both missing and null cases. Salvaged from PR #3217. Co-authored-by: erosika --- cli.py | 2 +- hermes_cli/main.py | 4 ++-- hermes_cli/runtime_provider.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli.py b/cli.py index 602844e49f..86ee7695bf 100644 --- a/cli.py +++ b/cli.py @@ -1083,7 +1083,7 @@ class HermesCLI: self.model = model or _config_model or _FALLBACK_MODEL # Auto-detect model from local server if still on fallback if self.model == _FALLBACK_MODEL: - _base_url = _model_config.get("base_url", "") if isinstance(_model_config, dict) else "" + _base_url = (_model_config.get("base_url") or "") if isinstance(_model_config, dict) else "" if "localhost" in _base_url or "127.0.0.1" in _base_url: from hermes_cli.runtime_provider import _auto_detect_local_model _detected = _auto_detect_local_model(_base_url) diff --git a/hermes_cli/main.py b/hermes_cli/main.py index 024a3e9122..375e28333d 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -832,8 +832,8 @@ def cmd_model(args): for entry in custom_providers_cfg: if not isinstance(entry, dict): continue - name = entry.get("name", "").strip() - base_url = entry.get("base_url", "").strip() + name = (entry.get("name") or "").strip() + base_url = (entry.get("base_url") or "").strip() if not name or not base_url: continue # Generate a stable key from the name diff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.py index 2b2df88bca..5d8edc1011 100644 --- a/hermes_cli/runtime_provider.py +++ b/hermes_cli/runtime_provider.py @@ -63,8 +63,8 @@ def _get_model_config() -> Dict[str, Any]: model_cfg = config.get("model") if isinstance(model_cfg, dict): cfg = dict(model_cfg) - default = cfg.get("default", "").strip() - base_url = cfg.get("base_url", "").strip() + default = (cfg.get("default") or "").strip() + base_url = (cfg.get("base_url") or "").strip() is_local = "localhost" in base_url or "127.0.0.1" in base_url is_fallback = not default or default == "anthropic/claude-opus-4.6" if is_local and is_fallback and base_url: