Kareadita/Kavita · error · KavitaException

errors.oidc.creating-user

Error message

errors.oidc.creating-user

What it means

Thrown by CreateNewAccount's catch-all: NewUserFromOpenIdConnect threw an exception that was not itself a KavitaException (those are rethrown verbatim). Any unexpected failure during account creation — DB error, Identity manager fault, missing dependency — is normalized to this generic message. The original exception is logged via LogError before the throw.

Source

Thrown at Kavita.Services/OidcService.cs:229

        if (settings.SyncUserSettings && !isAllowedToBeCreated)
        {
            logger.LogDebug("Login role was not found under claim {Claim} with prefix {Prefix}", settings.RolesClaim, settings.RolesPrefix);
            throw new KavitaException("errors.oidc.role-not-assigned");
        }

        try
        {
            return await NewUserFromOpenIdConnect(request, settings, principal, oidcId);
        }
        catch (KavitaException)
        {
            throw;
        }
        catch (Exception e)
        {
            logger.LogError(e, "An error occured creating a new user");
            throw new KavitaException("errors.oidc.creating-user");
        }

    }

    /// <summary>
    /// Find the best available name from claims
    /// </summary>
    /// <param name="claimsPrincipal"></param>
    /// <param name="orEqualTo">Also return if the claim is equal to this value</param>
    /// <returns></returns>
    public async Task<string?> FindBestAvailableName(ClaimsPrincipal claimsPrincipal, string? orEqualTo = null)
    {
        var nameCandidates = new[]
        {
            claimsPrincipal.FindFirstValue(JwtRegisteredClaimNames.PreferredUsername),
            claimsPrincipal.FindFirstValue(ClaimTypes.Name),
            claimsPrincipal.FindFirstValue(ClaimTypes.GivenName),
            claimsPrincipal.FindFirstValue(ClaimTypes.Surname)

View on GitHub (pinned to 9c3e540000)

Solutions

  1. Read the preceding LogError entry — it logs the real exception (e) with 'An error occured creating a new user'.
  2. Resolve the underlying cause (DB connectivity, migration, constraint) identified in that log.
  3. If it's a race on duplicate username/email, ensure the principal's claims are unique before retry.
  4. Confirm GetDefaultTheme returns a non-null theme (seed themes / migrations applied).
Defensive patterns

Strategy: try-catch

Try / catch

try { var user = await oidcService.LoginOrCreate(Request, principal, ct); }
catch (KavitaException ex) when (ex.Message == "errors.oidc.creating-user")
{
    // The real exception is logged; surface a generic 'account creation failed, contact admin' message.
    return StatusCode(500, "Unable to create account. Check server logs.");
}

Prevention

When it happens

Trigger: Any non-KavitaException inside NewUserFromOpenIdConnect during first-time OIDC provisioning: userManager.CreateAsync infra failure, DB constraint violation, null theme from GetDefaultTheme, SeedUser throwing an unexpected exception type.

Common situations: DB unreachable or migration pending; unique-constraint collision (username/email race); default site theme missing; transient DB timeout during account creation.

Related errors


AI-assisted analysis of Kareadita/Kavita@9c3e540000 (2026-08-13). Data as JSON: /api/errors/6df15308dac1d1dd. Report an issue: GitHub.