Kareadita/Kavita · error · KavitaException

generic-create-temp-archive

Error message

generic-create-temp-archive

What it means

Thrown by ArchiveService.CreateZipForDownload (line 296) when ZipFile.CreateFromDirectory(tempLocation, zipPath) throws an AggregateException — the OS-level zip creation from the staged temp folder failed. The original AggregateException is logged. Commonly this is a path/permission/disk-space problem on the destination zip or the source temp folder rather than a corrupt input.

Source

Thrown at Kavita.Services/ArchiveService.cs:296

        directoryService.ExistOrCreate(tempLocation);

        if (!directoryService.CopyFilesToDirectory(files, tempLocation))
        {
            throw new KavitaException("bad-copy-files-for-download");
        }

        var zipPath = Path.Join(directoryService.TempDirectory, $"kavita_{tempFolder}_{dateString}.zip");
        try
        {
            ZipFile.CreateFromDirectory(tempLocation, zipPath);
            // Remove the folder as we have the zip
            directoryService.ClearAndDeleteDirectory(tempLocation);
        }
        catch (AggregateException ex)
        {
            logger.LogError(ex, "There was an issue creating temp archive");
            throw new KavitaException("generic-create-temp-archive");
        }

        return zipPath;
    }

    public string CreateZipFromFoldersForDownload(IList<string> files, string tempFolder, Func<Tuple<string, float>, Task> progressCallback)
    {
        var dateString = DateTime.UtcNow.ToShortDateString().Replace("/", "_");

        var potentialExistingFile = directoryService.FileSystem.FileInfo.New(Path.Join(directoryService.TempDirectory, $"kavita_{tempFolder}_{dateString}.cbz"));
        if (potentialExistingFile.Exists)
        {
            // A previous download exists, just return it immediately
            return potentialExistingFile.FullName;
        }

        // Extract all the files to a temp directory and create zip on that
        var tempLocation = Path.Join(directoryService.TempDirectory, $"{tempFolder}_{dateString}");

View on GitHub (pinned to 9c3e540000)

Solutions

  1. Check the logged AggregateException inner exceptions for the real IO error (UnauthorizedAccess, IOException, OutOfSpace).
  2. Ensure the Temp directory has adequate free space and write permissions.
  3. Guarantee the staging directory still exists at zip time (avoid concurrent ClearAndDeleteDirectory on the same key).

Example fix

// before
catch (AggregateException ex) {
    logger.LogError(ex, "There was an issue creating temp archive");
    throw new KavitaException("generic-create-temp-archive");
}

// after — log inner exceptions for diagnosis
catch (AggregateException ex) {
    foreach (var inner in ex.InnerExceptions) logger.LogError(inner, "zip create failure");
    throw new KavitaException("generic-create-temp-archive");
}
Defensive patterns

Strategy: try-catch

Try / catch

catch (KavitaException ex) { return BadRequest(await localizationService.TranslateAsync(UserId, ex.Message)); }
// Log inner exceptions for diagnosis:
catch (AggregateException ex) { foreach (var i in ex.InnerExceptions) logger.LogError(i, "zip inner"); throw new KavitaException("generic-create-temp-archive"); }

Prevention

When it happens

Trigger: A download request reaches the zipping stage (copy succeeded) but System.IO.Compression cannot produce the zip: tempLocation was concurrently removed, zipPath already exists/locked, or the volume is out of space.

Common situations: Another thread/process deleted tempLocation between copy and zip; destination filename collision with the existing-file fast path; anti-virus scanning/locking the new zip on Windows; disk full.

Related errors


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