{"record":{"id":"38ab3a066ad7be97","repo":"HKUDS/Vibe-Trading","slug":"invalid-trading-212-config-at-path-exc","errorCode":null,"errorMessage":"invalid Trading 212 config at {path}: {exc}","messagePattern":"invalid Trading 212 config at (.+?): (.+?)","errorType":"exception","errorClass":"Trading212ConfigError","httpStatus":null,"severity":"error","filePath":"agent/src/trading/connectors/trading212/sdk.py","lineNumber":147,"sourceCode":"    cfg = Trading212Config.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 Trading 212 config path.\"\"\"\n    return get_runtime_root() / CONFIG_FILENAME\n\n\ndef load_config() -> Trading212Config:\n    \"\"\"Load Trading 212 settings from ``~/.vibe-trading/trading212.json``.\"\"\"\n    path = config_path()\n    if not path.exists():\n        return Trading212Config()\n    try:\n        return Trading212Config.from_mapping(json.loads(path.read_text(encoding=\"utf-8\")))\n    except (OSError, ValueError, json.JSONDecodeError) as exc:\n        raise Trading212ConfigError(f\"invalid Trading 212 config at {path}: {exc}\") from exc\n\n\ndef save_config(config: Trading212Config) -> Path:\n    \"\"\"Persist Trading 212 settings with owner-only permissions.\"\"\"\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 check_status(config: Trading212Config | None = None) -> dict[str, Any]:\n    \"\"\"Check REST readiness and config completeness without mutating broker state.\"\"\"\n    cfg = config or load_config()\n    report: dict[str, Any] = {","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/trading/connectors/trading212/sdk.py#L129-L165","documentation":"Raised by load_config when the Trading 212 config file exists but cannot be read or parsed: reading raises OSError, or the JSON content is invalid (ValueError/JSONDecodeError), or Trading212Config.from_mapping rejects the payload. It chains the original exception so the underlying cause is preserved.","triggerScenarios":"Calling build_config, check_status, get_account_snapshot, get_account_cash, get_account_metadata, or get_positions when the config file at config_path() exists but contains malformed JSON, is unreadable (permissions, deleted mid-read), or has keys/values that fail Trading212Config.from_mapping validation.","commonSituations":"Hand-edited config file with a trailing comma or typo; empty file created accidentally; config written by an old version with renamed keys; file with wrong ownership/permissions; BOM or non-UTF8 encoding.","solutions":["Inspect the {path} in the message and run `python -m json.tool <path>` to find the JSON syntax error","Fix or restore the file's contents to a valid Trading212Config mapping","If keys were rejected, compare against Trading212Config.from_mapping's expected field names","As a last resort, delete/rename the file — load_config returns a default Trading212Config when it does not exist"],"exampleFix":"# before (config.json contains: {\"api_key\": \"k\",})\n# after\n{\"api_key\": \"k\"}","handlingStrategy":"validation","validationCode":"import json\nfrom pathlib import Path\n\ndef config_file_ok(path: Path) -> bool:\n    if not path.exists():\n        return True  # load_config returns defaults\n    try:\n        json.loads(path.read_text(encoding=\"utf-8\"))\n    except (OSError, ValueError):\n        return False\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    config = load_config()\nexcept Trading212ConfigError as exc:\n    logger.error(\"bad config file: %s\", exc)\n    config = Trading212Config()  # fall back to defaults / re-run setup","preventionTips":["Validate the config JSON before saving it (json.dumps round-trip)","Write configs programmatically via save_config rather than hand-editing","Keep config files in version-controlled templates with schema checks"],"tags":["trading212","config","json","file-io"],"backgroundTag":"invalid-config-file","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}