{"record":{"id":"49066f46cf43cf58","repo":"Kareadita/Kavita","slug":"name-already-in-use","errorCode":null,"errorMessage":"name-already-in-use","messagePattern":"name-already-in-use","errorType":"exception","errorClass":"KavitaException","httpStatus":500,"severity":"warning","filePath":"Kavita.Services/Reading/ReadingProfileService.cs","lineNumber":72,"sourceCode":"\n    public async Task<UserReadingProfileDto> UpdateReadingProfile(int userId, UserReadingProfileDto dto)\n    {\n        var profile = await unitOfWork.AppUserReadingProfileRepository.GetUserProfile(userId, dto.Id);\n        if (profile == null) throw new KavitaException(\"profile-does-not-exist\");\n\n        UpdateReaderProfileFields(profile, dto);\n        unitOfWork.AppUserReadingProfileRepository.Update(profile);\n\n        await unitOfWork.CommitAsync();\n        return mapper.Map<UserReadingProfileDto>(profile);\n    }\n\n    public async Task<UserReadingProfileDto> CreateReadingProfile(int userId, UserReadingProfileDto dto)\n    {\n        var user = await unitOfWork.UserRepository.GetUserByIdAsync(userId, AppUserIncludes.UserPreferences);\n        if (user == null) throw new UnauthorizedAccessException();\n\n        if (await unitOfWork.AppUserReadingProfileRepository.IsProfileNameInUse(userId, dto.Name)) throw new KavitaException(\"name-already-in-use\");\n\n        var newProfile = new AppUserReadingProfileBuilder(user.Id).Build();\n        UpdateReaderProfileFields(newProfile, dto);\n\n        unitOfWork.AppUserReadingProfileRepository.Add(newProfile);\n        user.ReadingProfiles.Add(newProfile);\n\n        await unitOfWork.CommitAsync();\n\n        return mapper.Map<UserReadingProfileDto>(newProfile);\n    }\n\n    public async Task<UserReadingProfileDto> PromoteImplicitProfile(int userId, int profileId, int? activeDeviceId)\n    {\n        // Get all the user's profiles including the implicit\n        var allUserProfiles = await unitOfWork.AppUserReadingProfileRepository.GetProfilesForUser(userId);\n        var profileToPromote = allUserProfiles.FirstOrDefault(rp => rp.Id == profileId);\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/Kareadita/Kavita/blob/9c3e5400007f8a0282f7d883f2ad5e71716e514d/Kavita.Services/Reading/ReadingProfileService.cs#L54-L90","documentation":"Thrown by CreateReadingProfile when IsProfileNameInUse(userId, dto.Name) is true — the user already has a reading profile with that exact name. The 'name-already-in-use' localization key is surfaced to the UI. This is a business-rule validation guard, not a system fault.","triggerScenarios":"User submits a new profile with a name identical to an existing profile of theirs; profile names are enforced unique per user.","commonSituations":"User forgets a profile name is taken; duplicate submit from a double-click; UI didn't pre-check name availability.","solutions":["Choose a different, unique profile name for the user.","Pre-check availability with IsProfileNameInUse before offering the create action in the UI.","If merging was intended, update the existing profile instead of creating a new one."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (await unitOfWork.AppUserReadingProfileRepository.IsProfileNameInUse(userId, dto.Name))\n    return Conflict(\"name-already-in-use\");\nawait profileService.CreateReadingProfile(userId, dto);","typeGuard":null,"tryCatchPattern":"try { await profileService.CreateReadingProfile(userId, dto); }\ncatch (KavitaException ex) when (ex.Message == \"name-already-in-use\") { return Conflict(ex.Message); }","preventionTips":["Pre-check name uniqueness with IsProfileNameInUse in the UI before submit.","Guard against double-submit (debounce the create button).","Suggest a unique name when a collision is detected."],"tags":["reading-profiles","validation","duplicate","business-rule"],"backgroundTag":null,"analyzedSha":"9c3e5400007f8a0282f7d883f2ad5e71716e514d","analyzedAt":"2026-08-13T19:06:05.897Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}