{"record":{"id":"00c45f863ef6ab64","repo":"infiniflow/ragflow","slug":"register-failed-msg","errorCode":null,"errorMessage":"Register failed: {msg}","messagePattern":"Register failed: (.+?)","errorType":"exception","errorClass":"AuthException","httpStatus":401,"severity":"error","filePath":"admin/client/user.py","lineNumber":57,"sourceCode":"            cipher = Cipher_pkcs1_v1_5.new(rsa_key)\n            password_base64 = base64.b64encode(line.encode(\"utf-8\")).decode(\"utf-8\")\n            encrypted_password = cipher.encrypt(password_base64.encode())\n            return base64.b64encode(encrypted_password).decode(\"utf-8\")\n    except Exception as exc:\n        raise AuthException(\"Password encryption unavailable; install pycryptodomex (uv sync --python 3.13 --group test).\") from exc\n    return crypt(password_plain)\n\n\ndef register_user(client: HttpClient, email: str, nickname: str, password: str) -> None:\n    password_enc = encrypt_password(password)\n    payload = {\"email\": email, \"nickname\": nickname, \"password\": password_enc}\n    res = client.request_json(\"POST\", \"/users\", use_api_base=True, auth_kind=None, json_body=payload)\n    if res.get(\"code\") == 0:\n        return\n    msg = res.get(\"message\", \"\")\n    if \"has already registered\" in msg:\n        return\n    raise AuthException(f\"Register failed: {msg}\")\n\n\ndef login_user(client: HttpClient, server_type: str, email: str, password: str) -> str:\n    password_enc = encrypt_password(password)\n    payload = {\"email\": email, \"password\": password_enc}\n    if server_type == \"admin\":\n        response = client.request(\"POST\", \"/admin/login\", use_api_base=True, auth_kind=None, json_body=payload)\n    else:\n        response = client.request(\"POST\", \"/auth/login\", use_api_base=True, auth_kind=None, json_body=payload)\n    try:\n        res = response.json()\n    except Exception as exc:\n        raise AuthException(f\"Login failed: invalid JSON response ({exc})\") from exc\n    if res.get(\"code\") != 0:\n        raise AuthException(f\"Login failed: {res.get('message')}\")\n    token = response.headers.get(\"Authorization\")\n    if not token:\n        raise AuthException(\"Login failed: missing Authorization header\")","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/admin/client/user.py#L39-L75","documentation":"Raised by register_user in the admin test client when POST /users (with API base) returns code != 0 and the message does not contain 'has already registered'. It wraps the server's rejection message, e.g. invalid email format, weak password, or nickname conflicts. The 'already registered' case is treated as success (idempotent) and silently returns.","triggerScenarios":"POST {email, nickname, password(base64/encrypted)} to /users returning non-zero code with a message other than duplicate registration — e.g. malformed email, password fails policy, tenant limits, or a validation error from the API server.","commonSituations":"Admin CLI/bootstrap scripts against a server whose password policy rejects the generated password; wrong API base URL hitting a route that returns a different error envelope; server version where registration is disabled.","solutions":["Read the embedded server message — it states the exact rejection reason","Verify the email/nickname/password values satisfy server-side validation rules","Confirm the API base URL and that POST /users is the correct registration endpoint for this server build","If the account exists, the duplicate case auto-passes; otherwise fix the reported field and re-run"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import re\n\nEMAIL_RE = re.compile(r\"^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$\")\n\ndef is_valid_registration(email: str, nickname: str, password: str) -> bool:\n    return bool(EMAIL_RE.match(email)) and bool(nickname.strip()) and len(password) >= 6\n\nif not is_valid_registration(email, nickname, password):\n    raise ValueError(\"Fix email/nickname/password before calling register_user\")","typeGuard":"def is_user_error(res: dict) -> bool:\n    \"\"\"True when the server rejected the payload for a user-fixable reason.\"\"\"\n    return res.get(\"code\") != 0 and \"has already registered\" not in res.get(\"message\", \"\")","tryCatchPattern":"try:\n    register_user(client, email, nickname, password)\nexcept AuthException as e:\n    msg = str(e)\n    if \"already registered\" in msg:\n        pass  # idempotent bootstrap — treat as success\n    elif \"email\" in msg.lower() or \"password\" in msg.lower():\n        fix_credentials_and_retry()  # user-fixable validation error\n    else:\n        raise  # server/config issue — surface it","preventionTips":["Validate email format and password policy client-side before POST /users","Treat 'already registered' as success in bootstrap scripts (the client already does)","Pin client and server versions so the registration payload schema matches"],"tags":["auth","registration","admin-client","python","api"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}