{"record":{"id":"b53e77b409fcc9e4","repo":"HKUDS/Vibe-Trading","slug":"invalid-alpaca-config-at-path-exc","errorCode":null,"errorMessage":"invalid Alpaca config at {path}: {exc}","messagePattern":"invalid Alpaca config at (.+?): (.+?)","errorType":"validation","errorClass":"AlpacaConfigError","httpStatus":null,"severity":"error","filePath":"agent/src/trading/connectors/alpaca/sdk.py","lineNumber":169,"sourceCode":"    cfg = AlpacaConfig.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 Alpaca config path.\"\"\"\n    return get_runtime_root() / CONFIG_FILENAME\n\n\ndef load_config() -> AlpacaConfig:\n    \"\"\"Load Alpaca settings from ``~/.vibe-trading/alpaca.json``.\"\"\"\n    path = config_path()\n    if not path.exists():\n        return AlpacaConfig()\n    try:\n        return AlpacaConfig.from_mapping(json.loads(path.read_text(encoding=\"utf-8\")))\n    except (OSError, ValueError, json.JSONDecodeError) as exc:\n        raise AlpacaConfigError(f\"invalid Alpaca config at {path}: {exc}\") from exc\n\n\ndef save_config(config: AlpacaConfig) -> Path:\n    \"\"\"Persist Alpaca 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\n# ---------------------------------------------------------------------------\n# TAP routing (opt-in credential isolation)\n# ---------------------------------------------------------------------------\n","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/trading/connectors/alpaca/sdk.py#L151-L187","documentation":"Wrapped error from load_config: the Alpaca config file exists but could not be read (OSError), parsed as JSON (json.JSONDecodeError), or validated by from_mapping (ValueError such as bad profile/feed). The original exception is chained, and the message embeds the file path and underlying reason so you can fix the exact file.","triggerScenarios":"config_path() exists and path.read_text raises (permissions, race deletion), json.loads fails on malformed JSON (trailing comma, comments, truncated file), or from_mapping raises for an invalid profile/feed value — all re-raised as AlpacaConfigError.","commonSituations":"Hand-edited config with a JSON syntax error (comments, single quotes, trailing commas); file truncated by a crashed save_config; file written with a different user so permissions deny reads; partial manual migration leaving invalid field values.","solutions":["Read the {exc} part of the message — it names the exact JSON syntax or validation problem","Validate the file with python -m json.tool <path> to pinpoint syntax errors","Fix invalid field values (profile/feed) per the from_mapping rules","Check file ownership/permissions (config is written owner-only) if the reason is an OSError","As a last resort, delete/rename the file — load_config returns a default AlpacaConfig() when it is absent"],"exampleFix":"// before\n// ~/.alpaca/config.json contains: {\"profile\": \"paper\",}   <- trailing comma\n{\n  \"profile\": \"paper\"\n}","handlingStrategy":"try-catch","validationCode":"import json\nfrom pathlib import Path\np = config_path()\nif p.exists():\n    json.loads(p.read_text(encoding=\"utf-8\"))  # raises early with a precise JSON error\n# plus verify profile/feed values against the allowed sets before load_config","typeGuard":null,"tryCatchPattern":"try:\n    config = load_config()\nexcept AlpacaConfigError as exc:\n    message = str(exc)\n    if \"invalid Alpaca config at\" in message:\n        # parse the embedded {exc}; fall back to defaults if the user consents\n        path.rename(path.with_suffix(\".json.bak\"))\n        config = AlpacaConfig()\n    else:\n        raise","preventionTips":["Only edit the config with save_config / structured tools, never a text editor","Run python -m json.tool on the file after manual edits","Keep an untouched backup before migrations","Ensure the process user owns the file (save_config writes owner-only permissions)"],"tags":["python","alpaca","json","configuration","file-io"],"backgroundTag":"config-file-parse-error","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}