{"record":{"id":"c7e75f3a8f4ac14e","repo":"HKUDS/Vibe-Trading","slug":"invalid-portfolio-settings-exc","errorCode":null,"errorMessage":"invalid portfolio settings: {exc}","messagePattern":"invalid portfolio settings: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"agent/src/portfolio/config.py","lineNumber":246,"sourceCode":"            self.path.with_name(\"connections.json\") if path is not None else None\n        )\n        self.connection_store = connection_store or ConnectionStore(connection_path)\n\n    def load(self) -> PortfolioSettings:\n        \"\"\"Read persisted settings, creating an empty file on first use.\n\n        Returns:\n            The validated settings currently on disk.\n\n        Raises:\n            ValueError: If the file is unreadable, is not a JSON object, or\n                fails validation.\n        \"\"\"\n        if self.path.exists():\n            try:\n                payload = json.loads(self.path.read_text(encoding=\"utf-8\"))\n            except (OSError, json.JSONDecodeError) as exc:\n                raise ValueError(f\"invalid portfolio settings: {exc}\") from exc\n            if not isinstance(payload, dict):\n                raise ValueError(\"invalid portfolio settings: root must be an object\")\n            settings = parse_settings(payload, self.connection_store)\n            if any(\"profile_id\" in source for source in payload.get(\"sources\", [])):\n                self.save(settings)\n            return settings\n\n        settings = PortfolioSettings()\n        self.save(settings)\n        return settings\n\n    def save(self, settings: PortfolioSettings | dict[str, Any]) -> PortfolioSettings:\n        \"\"\"Validate and atomically persist settings with owner-only permissions.\n\n        Args:\n            settings: Settings object or raw dict to validate and store.\n\n        Returns:","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/portfolio/config.py#L228-L264","documentation":"PortfolioSettingsStore.load wraps any OSError or JSONDecodeError raised while reading the settings file into a single ValueError with the underlying cause chained. It means the file exists but cannot be read or parsed, distinct from the downstream parse_settings schema errors.","triggerScenarios":"An unreadable file (permissions, I/O error) or malformed JSON at the configured settings path; any consumer (settings, sources, refresh, latest, reconnect_target, _fetch_fx) then propagates this error.","commonSituations":"Partial writes from a crashed process, permissions changed after a user switch, or manual edits introducing syntax errors in the settings file.","solutions":["Read the chained cause (__cause__) to see whether it is OSError (fix permissions/disk) or JSONDecodeError (fix syntax)","Repair the JSON with json.tool or restore from backup","Ensure only the library writes the file and the process has consistent permissions"],"exampleFix":"try:\n    settings = store.load()\nexcept ValueError as exc:\n    cause = exc.__cause__  # OSError vs json.JSONDecodeError\n    log.error(\"portfolio settings unreadable: %s (%s)\", exc, cause)","handlingStrategy":"try-catch","validationCode":"import json\ntry:\n    json.loads(store.path.read_text(encoding='utf-8'))\nexcept (OSError, json.JSONDecodeError) as exc:\n    alert(f'portfolio settings unreadable: {exc}')","typeGuard":"def settings_loadable(path) -> bool:\n    try:\n        return isinstance(json.loads(path.read_text(encoding='utf-8')), dict)\n    except (OSError, json.JSONDecodeError):\n        return False","tryCatchPattern":"try:\n    settings = store.load()\nexcept ValueError as exc:\n    cause = exc.__cause__\n    if isinstance(cause, OSError):\n        fix_permissions(store.path); settings = store.load()\n    elif isinstance(cause, json.JSONDecodeError):\n        settings = restore_settings_backup(store)","preventionTips":["Back up the settings file before manual edits","Keep file ownership/permissions stable across deployments","Inspect __cause__ to distinguish IO vs syntax problems"],"tags":["python","json","config","io-error"],"backgroundTag":"corrupt-json-file","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}