mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
feat: config structure validation — detect malformed YAML at startup (#5426)
Add validate_config_structure() that catches common config.yaml mistakes: - custom_providers as dict instead of list (missing '-' in YAML) - fallback_model accidentally nested inside another section - custom_providers entries missing required fields (name, base_url) - Missing model section when custom_providers is configured - Root-level keys that look like misplaced custom_providers fields Surface these diagnostics at three levels: 1. Startup: print_config_warnings() runs at CLI and gateway module load, so users see issues before hitting cryptic errors 2. Error time: 'Unknown provider' errors in auth.py and model_switch.py now include config diagnostics with fix suggestions 3. Doctor: 'hermes doctor' shows a Config Structure section with all issues and fix hints Also adds a warning log in runtime_provider.py when custom_providers is a dict (previously returned None silently). Motivated by a Discord user who had malformed custom_providers YAML and got only 'Unknown Provider' with no guidance on what was wrong. 17 new tests covering all validation paths.
This commit is contained in:
parent
9ca954a274
commit
dce5f51c7c
8 changed files with 443 additions and 9 deletions
|
|
@ -419,14 +419,25 @@ def switch_model(
|
|||
# Resolve the provider
|
||||
pdef = resolve_provider_full(explicit_provider, user_providers)
|
||||
if pdef is None:
|
||||
_switch_err = (
|
||||
f"Unknown provider '{explicit_provider}'. "
|
||||
f"Check 'hermes model' for available providers, or define it "
|
||||
f"in config.yaml under 'providers:'."
|
||||
)
|
||||
# Check for common config issues that cause provider resolution failures
|
||||
try:
|
||||
from hermes_cli.config import validate_config_structure
|
||||
_cfg_issues = validate_config_structure()
|
||||
if _cfg_issues:
|
||||
_switch_err += "\n\nRun 'hermes doctor' — config issues detected:"
|
||||
for _ci in _cfg_issues[:3]:
|
||||
_switch_err += f"\n • {_ci.message}"
|
||||
except Exception:
|
||||
pass
|
||||
return ModelSwitchResult(
|
||||
success=False,
|
||||
is_global=is_global,
|
||||
error_message=(
|
||||
f"Unknown provider '{explicit_provider}'. "
|
||||
f"Check 'hermes model' for available providers, or define it "
|
||||
f"in config.yaml under 'providers:'."
|
||||
),
|
||||
error_message=_switch_err,
|
||||
)
|
||||
|
||||
target_provider = pdef.id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue