{"record":{"id":"66d9b67862568e59","repo":"666ghj/MiroFish","slug":"platform","errorCode":null,"errorMessage":"不支持的平台: {platform}","messagePattern":"不支持的平台: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/app/services/simulation_manager.py","lineNumber":511,"sourceCode":"                \n                state = self._load_simulation_state(sim_id)\n                if state:\n                    if project_id is None or state.project_id == project_id:\n                        simulations.append(state)\n        \n        return simulations\n    \n    def get_profiles(self, simulation_id: str, platform: str = None) -> List[Dict[str, Any]]:\n        \"\"\"获取模拟的Agent Profile\"\"\"\n        state = self._load_simulation_state(simulation_id)\n        if not state:\n            raise ValueError(f\"模拟不存在: {simulation_id}\")\n\n        if platform is None:\n            platform = state.get_default_platform()\n\n        if platform not in {\"twitter\", \"reddit\"}:\n            raise ValueError(f\"不支持的平台: {platform}\")\n\n        sim_dir = self._get_simulation_dir(simulation_id)\n        profile_path = os.path.join(\n            sim_dir,\n            \"twitter_profiles.csv\" if platform == \"twitter\" else \"reddit_profiles.json\",\n        )\n        \n        if not os.path.exists(profile_path):\n            return []\n\n        if platform == \"twitter\":\n            import csv\n\n            with open(profile_path, 'r', encoding='utf-8', newline='') as f:\n                return list(csv.DictReader(f))\n\n        with open(profile_path, 'r', encoding='utf-8') as f:\n            return json.load(f)","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/666ghj/MiroFish/blob/b5b53acc57189a4a42e44a23e149dc655c98fe82/backend/app/services/simulation_manager.py#L493-L529","documentation":"Raised in SimulationManager.get_profiles: after defaulting platform from the simulation state, the value must be exactly 'twitter' or 'reddit'. Anything else raises ValueError('不支持的平台: ...'). This guards the downstream file selection (twitter_profiles.csv vs reddit_profiles.json) which only implements those two platforms.","triggerScenarios":"Caller passes platform='weibo'/'discord'/etc.; persisted state's default platform is a legacy or invalid value; case mismatch ('Twitter'); platform key missing from state and get_default_platform returning something unexpected.","commonSituations":"New platform added to the frontend but not the backend; stored simulation state from an older version with a different platform vocabulary; case-sensitive comparison catching 'Twitter'; client sending a platform the API never supported.","solutions":["Pass platform='twitter' or 'reddit' exactly (lowercase), or omit it to use the simulation's default.","If state's default platform is invalid legacy data, fix/normalize the stored value (migration or manual edit) to twitter/reddit.","Add the missing platform to the backend: extend the set, add its profile file format in get_profiles, and its runner script path.","Normalize input with platform.strip().lower() at the API boundary."],"exampleFix":"# before\nprofiles = manager.get_profiles(sim_id, platform=request.query_params['platform'])\n# after\nplatform = request.query_params.get('platform', '').strip().lower() or None\nif platform not in (None, 'twitter', 'reddit'):\n    raise HTTPException(400, f'unsupported platform: {platform}')\nprofiles = manager.get_profiles(sim_id, platform=platform)","handlingStrategy":"validation","validationCode":"platform = (platform or '').strip().lower() or None\nif platform not in (None, 'twitter', 'reddit'):\n    raise HTTPException(400, f'unsupported platform: {platform}')","typeGuard":"def is_supported_platform(platform: object) -> bool:\n    return isinstance(platform, str) and platform.strip().lower() in {'twitter', 'reddit'}","tryCatchPattern":null,"preventionTips":["Normalize platform input (strip + lower) at the API boundary.","Keep the supported-platform set in one constant shared by route validation and the manager.","When adding a platform, update backend support (profile files, runner scripts) before shipping the UI option."],"tags":["simulation","platform","validation","profiles"],"backgroundTag":null,"analyzedSha":"b5b53acc57189a4a42e44a23e149dc655c98fe82","analyzedAt":"2026-08-14T22:29:33.146Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}