jlcodes99/cockpit-tools · warning

[TraeAutoCheckin] 保存自动签到日志失败:

Error message

[TraeAutoCheckin] 保存自动签到日志失败:

What it means

saveTraeAutoCheckinLogs persists the Trae auto-checkin log array to localStorage under LOGS_KEY and notifies listeners via a window event. It wraps all persistence in try/catch and logs a warning instead of throwing, because saving checkin history is non-critical and a quota or storage failure should not break the checkin flow.

Source

Thrown at src/services/traeAutoCheckinService.ts:205

  } catch {
    return [];
  }
}

export function saveTraeAutoCheckinLogs(logs: TraeAutoCheckinLogRecord[]): void {
  if (typeof window === 'undefined') {
    return;
  }
  try {
    const now = Date.now();
    const validLogs = logs.filter((log) => {
      const logTime = new Date(log.timestamp.replace(' ', 'T')).getTime();
      return !isNaN(logTime) && now - logTime <= THIRTY_DAYS_MS;
    });
    localStorage.setItem(LOGS_KEY, JSON.stringify(validLogs));
    window.dispatchEvent(new Event(TRAE_AUTO_CHECKIN_LOGS_CHANGED_EVENT));
  } catch (err) {
    console.warn('[TraeAutoCheckin] 保存自动签到日志失败:', err);
  }
}

export function addTraeAutoCheckinLog(record: TraeAutoCheckinLogRecord): void {
  const currentLogs = getTraeAutoCheckinLogs();
  const existingIndex = currentLogs.findIndex((l) => l.date === record.date);

  if (existingIndex < 0) {
    saveTraeAutoCheckinLogs([record, ...currentLogs]);
    return;
  }

  const existing = currentLogs[existingIndex];
  if (!existing) {
    saveTraeAutoCheckinLogs([record, ...currentLogs]);
    return;
  }

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Trim stored logs more aggressively (fewer than 30 days or cap count) before writing
  2. Clear other localStorage keys or call clearTraeAutoCheckinLogs to free quota
  3. Check that localStorage is accessible (try a test write) and warn users in private-mode contexts
  4. Accept the warning: the app intentionally continues without persisted logs

Example fix

// before
localStorage.setItem(LOGS_KEY, JSON.stringify(validLogs));
// after
const trimmed = validLogs.slice(-500);
try {
  localStorage.setItem(LOGS_KEY, JSON.stringify(trimmed));
} catch (err) {
  console.warn('[TraeAutoCheckin] 保存自动签到日志失败:', err);
}
Defensive patterns

Strategy: try-catch

Validate before calling

function canWriteLocalStorage(): boolean {
  try { localStorage.setItem('__probe__', '1'); localStorage.removeItem('__probe__'); return true; }
  catch { return false; }
}

Try / catch

try {
  localStorage.setItem(LOGS_KEY, JSON.stringify(validLogs.slice(-500)));
} catch (err) {
  if (err instanceof DOMException && err.name === 'QuotaExceededError') trimAndRetry();
  else console.warn('[TraeAutoCheckin] 保存自动签到日志失败:', err);
}

Prevention

When it happens

Trigger: localStorage.setItem throws when the serialized log JSON exceeds the ~5MB browser quota, when storage is disabled (private mode, denied permission), or when JSON.stringify produces an unexpected failure while filtering logs to the last 30 days.

Common situations: Long-running installs accumulating many accounts/logs until quota is hit; Safari private browsing where setItem always throws; enterprise browsers with localStorage disabled by policy.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/d3d7806f9c88aa31. Report an issue: GitHub.