Kareadita/Kavita · warning · KavitaException
library-doesnt-exist
library-doesnt-exist
Error message
library-doesnt-exist
What it means
Thrown by LibraryController.DeleteLibrary when GetLibraryForIdAsync returns null for the given libraryId (after the scan-running check). Message is localization key 'library-doesnt-exist'; a KavitaException surfacing as HTTP 500 unless handled earlier.
Source
Thrown at Kavita.Server/Controllers/LibraryController.cs:570
private async Task<bool> DeleteLibrary(int libraryId, int userId, CancellationToken ct = default)
{
var series = await unitOfWork.SeriesRepository.GetSeriesForLibraryIdAsync(libraryId, ct: ct);
var seriesIds = series.Select(x => x.Id).ToArray();
var chapterIds =
await unitOfWork.SeriesRepository.GetChapterIdsForSeriesAsync(seriesIds, ct);
try
{
if (TaskScheduler.HasScanTaskRunningForLibrary(libraryId))
{
logger.LogInformation("User is attempting to delete a library while a scan is in progress");
throw new KavitaException(await localizationService.TranslateAsync(userId, "delete-library-while-scan"));
}
var library = await unitOfWork.LibraryRepository.GetLibraryForIdAsync(libraryId, ct: ct);
if (library == null)
{
throw new KavitaException(await localizationService.TranslateAsync(userId, "library-doesnt-exist"));
}
// Due to a bad schema that I can't figure out how to fix, we need to erase all RelatedSeries before we delete the library
// Aka SeriesRelation has an invalid foreign key
foreach (var s in await unitOfWork.SeriesRepository.GetSeriesForLibraryIdAsync(library.Id, SeriesIncludes.Related, ct))
{
s.Relations = new List<SeriesRelation>();
unitOfWork.SeriesRepository.Update(s);
}
await unitOfWork.CommitAsync(ct);
unitOfWork.LibraryRepository.Delete(library);
var streams = await unitOfWork.UserRepository.GetSideNavStreamsByLibraryId(library.Id, ct);
unitOfWork.UserRepository.Delete(streams);
View on GitHub (pinned to 9c3e540000)
Solutions
- Refresh the library list on the client and confirm the id still exists before deleting.
- Treat the error as success if the goal (library gone) is already met.
- Pass the correct, current libraryId from the UI.
Defensive patterns
Strategy: validation
Validate before calling
var lib = await unitOfWork.LibraryRepository.GetLibraryForIdAsync(id, ct); if (lib is null) return NotFound();
Try / catch
try { await DeleteLibrary(id, userId, ct); }
catch (KavitaException) when (/* library-doesnt-exist */) { return NoContent(); } Prevention
- Refresh the library list before deleting.
- Treat 'already gone' as success.
- Pass the current libraryId from fresh UI state.
When it happens
Trigger: DELETE /api/library with a libraryId that does not exist in the database — already deleted, wrong id, or stale client state.
Common situations: Library was already removed in another session; client holds a stale id; race between two admins deleting the same library.
Related errors
- delete-library-while-scan
- invalid-metadata-provider
- profile-does-not-exist
- Path not found in CBL repository: {path}
- series-doesnt-exist
AI-assisted analysis of Kareadita/Kavita@9c3e540000 (2026-08-13).
Data as JSON: /api/errors/8b5dd717bb3bda46.
Report an issue: GitHub.