jlcodes99/cockpit-tools · warning
[TraeAutoCheckin] 保存配置失败:
Error message
[TraeAutoCheckin] 保存配置失败:
What it means
saveTraeAutoCheckinConfig in src/services/traeAutoCheckinService.ts:64 persists the auto-checkin config via localStorage.setItem(CONFIG_KEY, JSON.stringify(config)). If that throws (or the preceding dispatch fails), it warns '[TraeAutoCheckin] 保存配置失败:' with the error and returns silently — the in-memory config change is not persisted, so it will be lost on reload.
Source
Thrown at src/services/traeAutoCheckinService.ts:64
enabled: typeof parsed.enabled === 'boolean' ? parsed.enabled : false,
startTime: isValidTime(parsed.startTime) ? parsed.startTime : '06:00',
endTime: isValidTime(parsed.endTime) ? parsed.endTime : '12:00',
lastCheckedDate: typeof parsed.lastCheckedDate === 'string' ? parsed.lastCheckedDate : undefined,
};
} catch {
return DEFAULT_TRAE_AUTO_CHECKIN_CONFIG;
}
}
export function saveTraeAutoCheckinConfig(config: TraeAutoCheckinConfig): void {
if (typeof window === 'undefined') {
return;
}
try {
localStorage.setItem(CONFIG_KEY, JSON.stringify(config));
window.dispatchEvent(new Event(TRAE_AUTO_CHECKIN_CONFIG_CHANGED_EVENT));
} catch (err) {
console.warn('[TraeAutoCheckin] 保存配置失败:', err);
}
}
export function parseTimeToMinutes(timeStr: string): number {
const parts = timeStr.split(':').map(Number);
const h = parts[0] ?? 0;
const m = parts[1] ?? 0;
return h * 60 + m;
}
export function getTodayDateString(): string {
const now = new Date();
const pad = (n: number) => String(n).padStart(2, '0');
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
}
export function formatTimeOnly(date: Date = new Date()): string {
const pad = (n: number) => String(n).padStart(2, '0');View on GitHub (pinned to 1ed8b77992)
Solutions
- Open devtools and run localStorage.setItem manually to confirm whether storage writes work at all; exit private mode or enable storage.
- Clear old localStorage entries to free quota if a QuotaExceededError was logged.
- Validate the config object is JSON-serializable (no circular references or functions) before setItem.
- Add a user-visible notification or in-memory fallback so a failed save is not silently lost on reload.
Example fix
// before
} catch (err) {
console.warn('[TraeAutoCheckin] 保存配置失败:', err);
}
// after
} catch (err) {
console.warn('[TraeAutoCheckin] 保存配置失败:', err);
window.alert('自动签到配置保存失败,请检查浏览器存储设置');
} Defensive patterns
Strategy: try-catch
Validate before calling
// Verify storage is writable before saving:
try {
localStorage.setItem('__probe__', '1');
localStorage.removeItem('__probe__');
} catch {
console.warn('localStorage unavailable; config cannot be saved');
} Type guard
function canPersistToLocalStorage(): boolean {
try { localStorage.setItem('__t', '1'); localStorage.removeItem('__t'); return true; } catch { return false; }
} Try / catch
try {
localStorage.setItem(CONFIG_KEY, JSON.stringify(config));
} catch (err) {
console.warn('[TraeAutoCheckin] 保存配置失败:', err);
keepInMemoryFallbackConfig(config); // survive until storage works
} Prevention
- Check storage availability (private mode, quota) before relying on persistence.
- Keep the config object JSON-safe — no circular refs or functions.
- Notify the user when a save silently fails instead of only console.warn.
When it happens
Trigger: Calling saveTraeAutoCheckinConfig when localStorage write throws: storage quota exceeded, browser privacy/incognito mode blocking storage, localStorage disabled, or the page is in a sandboxed iframe with storage partitioning restrictions.
Common situations: Browser in private browsing with storage disabled; quota full from other large keys; embedded webview with disabled DOM storage; serialization of the config failing due to a non-JSON-safe value (circular structure) added to config.
Related errors
- [TraeAutoCheckin] 保存自动签到日志失败:
- [AccountStore] 删除持久化数据失败: ${name}
- [AccountStore] 本地缓存空间不足,已自动清理账号缓存并回退为仅内存态。
- Failed to save active page to localStorage:
- [AntigravityRuntime] failed to resolve preferred target:
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/778ba0e1f3ed7dca.
Report an issue: GitHub.