datawhalechina/hello-agents · warning · HTTPException

配置文件 {name} 不存在

Error message

配置文件 {name} 不存在

What it means

The GET config endpoint in src/api/config.py special-cases CONFIG (config.json, auto-created on demand) but for every other name calls ws.load_config(name) and raises HTTPException(404, '配置文件 {name} 不存在') when it returns None. So the 404 means the workspace has no config file matching the requested name — either the name is not one the workspace knows (AGENTS, BOOTSTRAP, ...) or the corresponding .md file genuinely is not on disk.

Source

Thrown at Co-creation-projects/tino-chen-HelloClaw/src/api/config.py:80

    configs.insert(0, "CONFIG")
    return {"configs": configs}


@router.get("/{name}")
async def get_config(name: str, ws: WorkspaceManager = Depends(get_workspace)):
    """获取指定配置文件内容"""
    # 特殊处理 CONFIG (config.json)
    if name == "CONFIG":
        ensure_config_json_exists()
        config_path = get_config_json_path()
        with open(config_path, "r", encoding="utf-8") as f:
            content = f.read()
        return {"name": name, "content": content}

    # 处理 .md 配置文件
    content = ws.load_config(name)
    if content is None:
        raise HTTPException(status_code=404, detail=f"配置文件 {name} 不存在")
    return {"name": name, "content": content}


@router.put("/{name}")
async def update_config(name: str, request: ConfigUpdateRequest, ws: WorkspaceManager = Depends(get_workspace)):
    """更新配置文件"""
    # 特殊处理 CONFIG (config.json)
    if name == "CONFIG":
        ensure_config_json_exists()
        # 严格校验 JSON 格式
        try:
            config_data = json.loads(request.content)
        except json.JSONDecodeError as e:
            raise HTTPException(status_code=400, detail=f"无效的 JSON 格式: {str(e)}")

        # 校验必需字段
        if not isinstance(config_data, dict):
            raise HTTPException(status_code=400, detail="配置必须是 JSON 对象")

View on GitHub (pinned to 606a07d341)

Solutions

  1. Discover valid names first: call the list endpoint of the config router (or ws.list_configs()) and use an exact name from it.
  2. Match the expected casing/suffix — the route takes the bare name (AGENTS), not the filename (AGENTS.md).
  3. If the workspace is new, complete its initialization/onboarding so standard config files are created.
  4. Treat 404 on this route in clients as 'not created yet' and offer a create action (PUT the config) instead of erroring out.

Example fix

# before
r = requests.get(f"{base}/api/config/AGENTS.md")  # 404
# after
names = requests.get(f"{base}/api/config").json()  # list valid config names
r = requests.get(f"{base}/api/config/AGENTS")  # exact bare name
r.raise_for_status()
Defensive patterns

Strategy: validation

Validate before calling

names = {c["name"] for c in requests.get(f"{base}/api/config").json()}
if name not in names:
    raise LookupError(f"config {name!r} not in workspace; available: {sorted(names)}")
content = requests.get(f"{base}/api/config/{name}").json()["content"]

Try / catch

resp = requests.get(f"{base}/api/config/{name}")
if resp.status_code == 404:
    # not created yet — create it via PUT instead of failing
    resp = requests.put(f"{base}/api/config/{name}", json={"content": default_content})
resp.raise_for_status()

Prevention

When it happens

Trigger: GET /api/config/foo where foo.md was never created; requesting a name with wrong case or extra suffix (/api/config/AGENTS.md instead of /api/config/AGENTS); workspace not initialized so no config files exist yet; file deleted by a user through the UI or filesystem.

Common situations: Frontend building the config list before onboarding finished; manual API calls guessing endpoint names; case-sensitivity differences between macOS dev and Linux prod; config removed via update/PUT flow leaving stale UI entries.

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/cff33795f581bd8a. Report an issue: GitHub.