Kareadita/Kavita · warning · KavitaException

total-logs

total-logs

Error message

total-logs

What it means

Range-validation error for the 'Total Logs' server setting, the number of days of log files Kavita keeps before cleanup. Identical in shape to the backups guard: the SettingsService throws KavitaException('total-logs') when TotalLogs is < 1 or > 30, again only when the value is changing. SettingsController maps it to HTTP 400 'Total Logs must be between 1 and 30'.

Source

Thrown at Kavita.Services/SettingsService.cs:457

            if (setting.Key == ServerSettingKey.TotalBackups &&
                updateSettingsDto.TotalBackups + string.Empty != setting.Value)
            {
                if (updateSettingsDto.TotalBackups > 30 || updateSettingsDto.TotalBackups < 1)
                {
                    throw new KavitaException("total-backups");
                }

                setting.Value = updateSettingsDto.TotalBackups + string.Empty;
                unitOfWork.SettingsRepository.Update(setting);
            }

            if (setting.Key == ServerSettingKey.TotalLogs &&
                updateSettingsDto.TotalLogs + string.Empty != setting.Value)
            {
                if (updateSettingsDto.TotalLogs > 30 || updateSettingsDto.TotalLogs < 1)
                {
                    throw new KavitaException("total-logs");
                }

                setting.Value = updateSettingsDto.TotalLogs + string.Empty;
                unitOfWork.SettingsRepository.Update(setting);
            }

            if (setting.Key == ServerSettingKey.EnableFolderWatching &&
                updateSettingsDto.EnableFolderWatching + string.Empty != setting.Value)
            {
                setting.Value = updateSettingsDto.EnableFolderWatching + string.Empty;
                unitOfWork.SettingsRepository.Update(setting);
            }
        }

        if (!unitOfWork.HasChanges()) return updateSettingsDto;

        try
        {

View on GitHub (pinned to 9c3e540000)

Solutions

  1. Set totalLogs to an integer between 1 and 30 inclusive and resend.
  2. Add client-side range validation (1..30) mirroring the backups field.
  3. Re-GET /api/settings to load the current value before editing.
  4. For scripted config, clamp the value into [1, 30] before posting.

Example fix

// before
{ totalLogs: 365 } // 'keep a year'

// after
{ totalLogs: 30 } // valid: 1..30
Defensive patterns

Strategy: validation

Validate before calling

// Run before POST /api/settings
function isValidRetention(n: unknown): n is number {
  return typeof n === 'number' && Number.isInteger(n) && n >= 1 && n <= 30;
}
if (!isValidRetention(dto.totalLogs)) {
  showError('Total Logs must be between 1 and 30');
  return;
}

Type guard

function isValidRetention(n: unknown): n is number {
  return typeof n === 'number' && Number.isInteger(n) && n >= 1 && n <= 30;
}

Prevention

When it happens

Trigger: POST /api/settings with totalLogs set to 0, negative, or greater than 30, where the value differs from the persisted setting.

Common situations: Admin sets 0 to 'disable logging retention'; very large value expecting indefinite log storage; default DTO has no initializer for TotalLogs so a malformed payload can post an out-of-range int; migrating settings from a version with different bounds.

Related errors


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