QuantumNous/new-api · warning · Error
Failed to clean logs
Error message
Failed to clean logs
What it means
First failure branch of handleCleanLogs: startLogCleanupTask(purgeTimestamp) resolved with success=false, so the code throws using the server's response.message (or the localized fallback). The catch converts it to an error toast; this is the business-error path, not a thrown HTTP error.
Source
Thrown at web/src/features/system-settings/maintenance/log-settings-section.tsx:286
if (!purgeTimestamp) {
toast.error(t('Select a timestamp before clearing logs.'))
return
}
setShowConfirmDialog(true)
}
const handleCleanLogs = async () => {
if (!purgeTimestamp) {
toast.error(t('Select a timestamp before clearing logs.'))
return
}
setIsStartingLogCleanup(true)
try {
const res = await startLogCleanupTask(purgeTimestamp)
if (!res.success) {
throw new Error(res.message || t('Failed to clean logs'))
}
if (!res.data) {
throw new Error(t('Failed to clean logs'))
}
setLogCleanupTask(res.data)
setShowConfirmDialog(false)
toast.success(t('Log cleanup task started.'))
} catch (error) {
const message =
error instanceof Error ? error.message : t('Failed to clean logs')
toast.error(message)
} finally {
setIsStartingLogCleanup(false)
}
}
const cleanupServerLogFiles = async () => {
if (View on GitHub (pinned to e2c7aa7b10)
Solutions
- Read the toast — it shows response.message from the server, which names the exact rejection reason.
- Ensure the selected timestamp is in the past, accounting for timezone conversion before sending.
- Wait for any in-progress cleanup task to finish (the panel tracks it via logCleanupTask state) before starting another.
- If the backend reports a DB error, check the log database connection and retry.
Defensive patterns
Strategy: validation
Validate before calling
// before calling startLogCleanupTask, clamp the timestamp to the past
const ts = purgeTimestamp instanceof Date ? purgeTimestamp.getTime() : Number(purgeTimestamp)
if (!Number.isFinite(ts) || ts > Date.now()) {
toast.error(t('Select a timestamp before clearing logs.'))
return
}
const res = await startLogCleanupTask(ts) Try / catch
try {
const res = await startLogCleanupTask(purgeTimestamp)
if (!res.success) throw new Error(res.message || t('Failed to clean logs'))
...
} catch (error) {
toast.error(error instanceof Error ? error.message : t('Failed to clean logs'))
} Prevention
- Client-side validate that the chosen timestamp is finite and strictly in the past (timezone-aware).
- Disable the start button while another cleanup task is active.
- Always display response.message from the server; it carries the exact rejection reason.
When it happens
Trigger: POST start-log-cleanup with a timestamp the backend rejects: purge time in the future, insufficient admin permission, a cleanup task already running, or a server-side error enqueuing the task.
Common situations: Admin picks a date/time whose timezone conversion lands in the future (frontend sends local-time-derived timestamp); a previous cleanup task is still in progress; token expired mid-session; log DB unreachable.
Related errors
- We could not load instances.
- Failed to update channel
- Failed to create channel
- Failed to fetch usage
- Failed to fetch reset credit details
AI-assisted analysis of QuantumNous/new-api@e2c7aa7b10 (2026-08-15).
Data as JSON: /api/errors/71d6a8ffaf601a54.
Report an issue: GitHub.