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
- Trim stored logs more aggressively (fewer than 30 days or cap count) before writing
- Clear other localStorage keys or call clearTraeAutoCheckinLogs to free quota
- Check that localStorage is accessible (try a test write) and warn users in private-mode contexts
- 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
- Cap stored log count/date range before serializing
- Probe storage availability at app startup
- Periodically prune legacy keys to keep quota headroom
- Treat logs as disposable; never let log persistence break checkin flow
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
- [AccountStore] 本地缓存空间不足,已自动清理账号缓存并回退为仅内存态。
- Failed to save active page to localStorage:
- [TraeAutoCheckin] 保存配置失败:
- [WorkbuddyAutoCheckin] 本地缓存保存失败:
- [AccountStore] 清理超限缓存失败:
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/d3d7806f9c88aa31.
Report an issue: GitHub.