HKUDS/Vibe-Trading · error · MT5ConfigError
invalid MT5 config at {path}: {exc}
Error message
invalid MT5 config at {path}: {exc} What it means
load_config reads the MT5 config JSON file and wraps any OSError, ValueError or JSONDecodeError from reading/parsing into MT5ConfigError with the offending path. It fires before any connection, purely at file/parse level; a missing file is fine (defaults), but an unreadable or malformed one is not.
Source
Thrown at agent/src/trading/connectors/mt5/_client.py:158
cfg = MT5Config.from_mapping(base)
clean = {k: v for k, v in dict(overrides or {}).items() if k in _OVERRIDE_KEYS and v not in (None, "")}
return cfg.with_overrides(**clean) if clean else cfg
def config_path() -> Path:
"""Return the user-level MT5 config path."""
return get_runtime_root() / CONFIG_FILENAME
def load_config() -> MT5Config:
"""Load MT5 settings from ``~/.vibe-trading/mt5.json``."""
path = config_path()
if not path.exists():
return MT5Config()
try:
return MT5Config.from_mapping(json.loads(path.read_text(encoding="utf-8")))
except (OSError, ValueError, json.JSONDecodeError) as exc:
raise MT5ConfigError(f"invalid MT5 config at {path}: {exc}") from exc
def save_config(config: MT5Config) -> Path:
"""Persist MT5 settings with owner-only permissions (best-effort on Windows)."""
path = config_path()
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(asdict(config), indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
try:
path.chmod(0o600)
except OSError:
pass
return path
def mt5_available() -> bool:
"""Return whether the optional ``MetaTrader5`` package can be imported."""
try:
_require_mt5()View on GitHub (pinned to 80ffdda44c)
Solutions
- Validate the file: python -m json.tool ~/.vibe-trading/mt5.json and fix the reported syntax error
- Check permissions: ls -l ~/.vibe-trading/mt5.json, chmod 600 if needed
- If the file is corrupt beyond repair, delete it — load_config returns defaults when it's absent, then re-save settings
Example fix
// before
{ "profile": "paper", "login": 123, }
// after
{ "profile": "paper", "login": 123 } Defensive patterns
Strategy: validation
Validate before calling
import json, pathlib
p = pathlib.Path.home() / '.vibe-trading/mt5.json'
if p.exists():
json.loads(p.read_text(encoding='utf-8')) # raises early with a clear JSON error Try / catch
try:
cfg = load_config()
except MT5ConfigError as e:
logger.error('Config unreadable: %s', e)
# fall back to defaults or prompt re-setup; do not trade with guessed config
cfg = MT5Config() Prevention
- Validate JSON in CI/editor before deploy
- Never edit the config while the app is writing it
- Keep backups so corrupt files can be restored instead of hand-repaired
When it happens
Trigger: ~/.vibe-trading/mt5.json exists but has a JSON syntax error (trailing comma, comments, truncated), or the file can't be read due to permissions. Raised from load_config, which build_config and all trading entry points call.
Common situations: Hand-editing the JSON and leaving a trailing comma or single quotes; a crashed save left a partial file; file owned by another user (permission denied).
Related errors
- Feishu QR login requires a JSON agent config; use ~/.vibe-tr
- agent config 'channels' must be an object
- agent config 'channels.feishu' must be an object
- Agent config must decode to a JSON/YAML object
- sources must be a list
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/d21f592c68560f09.
Report an issue: GitHub.