666ghj/MiroFish · error · ValueError
不支持的平台: {platform}
Error message
不支持的平台: {platform} What it means
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.
Source
Thrown at backend/app/services/simulation_manager.py:511
state = self._load_simulation_state(sim_id)
if state:
if project_id is None or state.project_id == project_id:
simulations.append(state)
return simulations
def get_profiles(self, simulation_id: str, platform: str = None) -> List[Dict[str, Any]]:
"""获取模拟的Agent Profile"""
state = self._load_simulation_state(simulation_id)
if not state:
raise ValueError(f"模拟不存在: {simulation_id}")
if platform is None:
platform = state.get_default_platform()
if platform not in {"twitter", "reddit"}:
raise ValueError(f"不支持的平台: {platform}")
sim_dir = self._get_simulation_dir(simulation_id)
profile_path = os.path.join(
sim_dir,
"twitter_profiles.csv" if platform == "twitter" else "reddit_profiles.json",
)
if not os.path.exists(profile_path):
return []
if platform == "twitter":
import csv
with open(profile_path, 'r', encoding='utf-8', newline='') as f:
return list(csv.DictReader(f))
with open(profile_path, 'r', encoding='utf-8') as f:
return json.load(f)View on GitHub (pinned to b5b53acc57)
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.
Example fix
# before
profiles = manager.get_profiles(sim_id, platform=request.query_params['platform'])
# after
platform = request.query_params.get('platform', '').strip().lower() or None
if platform not in (None, 'twitter', 'reddit'):
raise HTTPException(400, f'unsupported platform: {platform}')
profiles = manager.get_profiles(sim_id, platform=platform) Defensive patterns
Strategy: validation
Validate before calling
platform = (platform or '').strip().lower() or None
if platform not in (None, 'twitter', 'reddit'):
raise HTTPException(400, f'unsupported platform: {platform}') Type guard
def is_supported_platform(platform: object) -> bool:
return isinstance(platform, str) and platform.strip().lower() in {'twitter', 'reddit'} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 模拟不存在: {simulation_id}
- 启用图谱记忆更新时必须提供 graph_id
- t('step5.selectAgentFirst')
- graph_id is required
- At least one text chunk is required
AI-assisted analysis of 666ghj/MiroFish@b5b53acc57 (2026-08-14).
Data as JSON: /api/errors/66d9b67862568e59.
Report an issue: GitHub.