{"record":{"id":"57db8a60bbd4a4a8","repo":"datawhalechina/hello-agents","slug":"error-57db8a","errorCode":null,"errorMessage":"用户不存在","messagePattern":"用户不存在","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"Co-creation-projects/Apricity-InnocoreAI/api/routes/users.py","lineNumber":60,"sourceCode":"        \n        return UserResponse(\n            id=user[\"id\"],\n            email=user[\"email\"],\n            profile=user[\"profile\"],\n            created_at=user[\"created_at\"].isoformat() if user[\"created_at\"] else \"\"\n        )\n        \n    except Exception as e:\n        logger.error(f\"创建用户失败: {str(e)}\")\n        raise HTTPException(status_code=500, detail=str(e))\n\n@router.get(\"/{user_id}\", response_model=UserResponse)\nasync def get_user(user_id: str):\n    \"\"\"获取用户信息\"\"\"\n    try:\n        user = await db_manager.get_user(user_id)\n        if not user:\n            raise HTTPException(status_code=404, detail=\"用户不存在\")\n        \n        return UserResponse(\n            id=user[\"id\"],\n            email=user[\"email\"],\n            profile=user[\"profile\"],\n            created_at=user[\"created_at\"].isoformat() if user[\"created_at\"] else \"\"\n        )\n        \n    except HTTPException:\n        raise\n    except Exception as e:\n        logger.error(f\"获取用户信息失败: {str(e)}\")\n        raise HTTPException(status_code=500, detail=str(e))\n\n@router.put(\"/{user_id}\", response_model=Dict[str, Any])\nasync def update_user(user_id: str, request: UserUpdateRequest):\n    \"\"\"更新用户信息\"\"\"\n    try:","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/Apricity-InnocoreAI/api/routes/users.py#L42-L78","documentation":"HTTPException 404 '用户不存在' at api/routes/users.py:60 raised when db_manager.get_user returns falsy for the given user_id in GET /users/{user_id}. The user row simply does not exist (never created, deleted, or wrong id format).","triggerScenarios":"GET /users/{user_id} with an id not present in the database; user deleted; id copied with whitespace/case differences if the DB collation is case-sensitive.","commonSituations":"Client stores a stale user id after DB reset; frontend passes undefined producing 'None'/'undefined' string ids; environment mismatch (querying dev DB for a prod-created user).","solutions":["Verify the id by listing users or checking the creation response that returned it.","Confirm you're pointed at the right database/environment.","Trim/validate the id client-side before the call.","If the user should exist, check the DB directly for the row and any deletion logic in db_manager."],"exampleFix":"// before\nconst user = await api.get(`/users/${userId}`);\n// after\nif (!userId || userId === 'undefined') throw new Error('missing userId');\nconst user = await api.get(`/users/${encodeURIComponent(userId.trim())}`);","handlingStrategy":"validation","validationCode":"assert user_id and user_id not in ('undefined','null','None')\nresp = await client.get(f\"/users/{user_id}\")\nif resp.status_code == 404: handle_missing_user()","typeGuard":"def is plausible_user_id(uid: str) -> bool:\n    return isinstance(uid, str) and len(uid.strip()) > 0 and uid not in {\"undefined\", \"null\"}","tryCatchPattern":"try:\n    user = await client.get(f\"/users/{user_id}\").json()\nexcept NotFoundError:\n    user = None  # first-run / deleted user; create if needed","preventionTips":["Derive user ids from a live session, not localStorage","Validate ids client-side before requests","Handle 404 as a state, not an error"],"tags":["fastapi","http-404","user-not-found","rest"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}