From df09a90cd6f43d4cbba490fc6663eb5edc616a35 Mon Sep 17 00:00:00 2001 From: Baophan00 <109447498+Baophan00@users.noreply.github.com> Date: Fri, 31 Jul 2026 20:27:46 +0700 Subject: [PATCH] fix(config): refuse to write when config.yaml has YAML syntax errors set_config_value() and unset_config_value() silently replaced the entire config with an empty dict when config.yaml could not be parsed. A single YAML syntax error would cause 'hermes config set' to wipe all settings and write only the new key. Now exits with error and preserves the existing file. --- hermes_cli/config.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/hermes_cli/config.py b/hermes_cli/config.py index 8419ba25f99f4..94f914d0cf986 100644 --- a/hermes_cli/config.py +++ b/hermes_cli/config.py @@ -4837,8 +4837,15 @@ def set_config_value(key: str, value: str, force: bool = False): try: with open(config_path, encoding="utf-8") as f: user_config = fast_safe_load(f) or {} - except Exception: - user_config = {} + except Exception as exc: + print( + f"✗ Cannot parse {config_path}: {exc}\n" + f" The file contains a YAML syntax error. Fix the error\n" + f" in your config file first, then retry.\n" + f" (hermes config edit will open it in your editor.)", + file=sys.stderr, + ) + sys.exit(1) # Handle nested keys (e.g., "tts.provider") including numeric list # indices (e.g., "custom_providers.0.api_key"). Delegates to @@ -5045,8 +5052,15 @@ def unset_config_value(key: str): try: with open(config_path, encoding="utf-8") as f: user_config = fast_safe_load(f) or {} - except Exception: - user_config = {} + except Exception as exc: + print( + f"✗ Cannot parse {config_path}: {exc}\n" + f" The file contains a YAML syntax error. Fix the error\n" + f" in your config file first, then retry.\n" + f" (hermes config edit will open it in your editor.)", + file=sys.stderr, + ) + sys.exit(1) removed = _unset_nested(user_config, key)