HKUDS/DeepTutor · error · HTTPException

User not found

Error message

User not found

What it means

HTTP 404 raised by PUT /profile when set_avatar returns false — typically because the current username has no user record in the store (e.g. PocketBase-mode identity or a stale token for a deleted user).

Solutions

  1. Verify the token belongs to an existing local user
  2. Re-login to refresh identity after user-store changes
  3. Create the missing user record via admin tooling if it was removed
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at deeptutor/api/routers/auth.py:640 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/dc9722851e0b8a84. Report an issue: GitHub.

Appendix: source

Thrown at deeptutor/api/routers/auth.py:640

            role=current.role,
            created_at="",
        )
    return UserInfo(**info)


@router.put("/profile")
async def update_profile(
    body: UpdateProfileRequest,
    payload: TokenPayload | None = Depends(require_auth),
) -> dict:
    """Update the current user's own avatar marker (icon choice or reset).

    Only the validated ``icon:<name>:<color>`` form (or empty string) is
    accepted here; ``img:`` markers are owned by the upload endpoint.
    """
    current = _require_profile_identity(payload)
    if not set_avatar(current.username, body.avatar):
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found")
    # The marker no longer references an uploaded image, so drop the file.
    from deeptutor.multi_user.identity import delete_avatar_file

    if current.user_id and _USER_ID_RE.match(current.user_id):
        delete_avatar_file(current.user_id)
    return {"ok": True, "avatar": body.avatar}


@router.put("/profile/avatar")
async def upload_avatar(
    file: UploadFile = File(...),
    payload: TokenPayload | None = Depends(require_auth),
) -> dict:
    """Upload an avatar image for the current user.

    The client is expected to crop/resize before uploading; the server only
    enforces a size cap and validates the format by magic bytes. Not available
    in PocketBase mode (those identities have no local user record).

View on GitHub (pinned to 3e82f13042)