{"record":{"id":"d21f592c68560f09","repo":"HKUDS/Vibe-Trading","slug":"invalid-mt5-config-at-path-exc","errorCode":null,"errorMessage":"invalid MT5 config at {path}: {exc}","messagePattern":"invalid MT5 config at (.+?): (.+?)","errorType":"exception","errorClass":"MT5ConfigError","httpStatus":null,"severity":"error","filePath":"agent/src/trading/connectors/mt5/_client.py","lineNumber":158,"sourceCode":"    cfg = MT5Config.from_mapping(base)\n    clean = {k: v for k, v in dict(overrides or {}).items() if k in _OVERRIDE_KEYS and v not in (None, \"\")}\n    return cfg.with_overrides(**clean) if clean else cfg\n\n\ndef config_path() -> Path:\n    \"\"\"Return the user-level MT5 config path.\"\"\"\n    return get_runtime_root() / CONFIG_FILENAME\n\n\ndef load_config() -> MT5Config:\n    \"\"\"Load MT5 settings from ``~/.vibe-trading/mt5.json``.\"\"\"\n    path = config_path()\n    if not path.exists():\n        return MT5Config()\n    try:\n        return MT5Config.from_mapping(json.loads(path.read_text(encoding=\"utf-8\")))\n    except (OSError, ValueError, json.JSONDecodeError) as exc:\n        raise MT5ConfigError(f\"invalid MT5 config at {path}: {exc}\") from exc\n\n\ndef save_config(config: MT5Config) -> Path:\n    \"\"\"Persist MT5 settings with owner-only permissions (best-effort on Windows).\"\"\"\n    path = config_path()\n    path.parent.mkdir(parents=True, exist_ok=True)\n    path.write_text(json.dumps(asdict(config), indent=2, ensure_ascii=False) + \"\\n\", encoding=\"utf-8\")\n    try:\n        path.chmod(0o600)\n    except OSError:\n        pass\n    return path\n\n\ndef mt5_available() -> bool:\n    \"\"\"Return whether the optional ``MetaTrader5`` package can be imported.\"\"\"\n    try:\n        _require_mt5()","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/trading/connectors/mt5/_client.py#L140-L176","documentation":"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.","triggerScenarios":"~/.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.","commonSituations":"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).","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"],"exampleFix":"// before\n{ \"profile\": \"paper\", \"login\": 123, }\n// after\n{ \"profile\": \"paper\", \"login\": 123 }","handlingStrategy":"validation","validationCode":"import json, pathlib\np = pathlib.Path.home() / '.vibe-trading/mt5.json'\nif p.exists():\n    json.loads(p.read_text(encoding='utf-8'))  # raises early with a clear JSON error","typeGuard":null,"tryCatchPattern":"try:\n    cfg = load_config()\nexcept MT5ConfigError as e:\n    logger.error('Config unreadable: %s', e)\n    # fall back to defaults or prompt re-setup; do not trade with guessed config\n    cfg = MT5Config()","preventionTips":["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"],"tags":["mt5","config","json","parse-error"],"backgroundTag":"config-file-parse-error","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}