jlcodes99/cockpit-tools · warning
[WorkbuddyAutoCheckin] 本地缓存保存失败:
Error message
[WorkbuddyAutoCheckin] 本地缓存保存失败:
What it means
cacheConfigLocally writes the Workbuddy auto-checkin config JSON to localStorage (CONFIG_KEY) as a mirror of the Rust-side config, optionally emitting a change event. A quota or disabled-storage error is caught and warned so the authoritative Rust config still wins.
Source
Thrown at src/services/workbuddyAutoCheckinService.ts:63
let cachedConfig: WorkbuddyAutoCheckinConfig | null = null;
function isValidTime(time: unknown): time is string {
return typeof time === 'string' && /^([01]\d|2[0-3]):[0-5]\d$/.test(time);
}
function cacheConfigLocally(config: WorkbuddyAutoCheckinConfig, emitChange = false): void {
cachedConfig = config;
if (typeof window === 'undefined') {
return;
}
try {
localStorage.setItem(CONFIG_KEY, JSON.stringify(config));
if (emitChange) {
window.dispatchEvent(new Event(WORKBUDDY_AUTO_CHECKIN_CONFIG_CHANGED_EVENT));
}
} catch (err) {
console.warn('[WorkbuddyAutoCheckin] 本地缓存保存失败:', err);
}
}
export async function getWorkbuddyAutoCheckinConfigAsync(): Promise<WorkbuddyAutoCheckinConfig> {
try {
const config = await invoke<WorkbuddyAutoCheckinConfig>('get_workbuddy_auto_checkin_config');
cacheConfigLocally(config);
return config;
} catch (err) {
console.warn('[WorkbuddyAutoCheckin] 从 Rust 端获取配置失败,使用本地缓存或默认值:', err);
return getWorkbuddyAutoCheckinConfig();
}
}
export function getWorkbuddyAutoCheckinConfig(): WorkbuddyAutoCheckinConfig {
if (cachedConfig) {
return cachedConfig;
}View on GitHub (pinned to 1ed8b77992)
Solutions
- Free localStorage quota (remove legacy/cached keys)
- Validate/normalize the config object before stringify
- Treat localStorage as a cache only — fall back to the Rust config (the code already does)
- Warn users in private-mode contexts that config caching is unavailable
Example fix
// before
localStorage.setItem(CONFIG_KEY, JSON.stringify(config));
// after
try {
localStorage.setItem(CONFIG_KEY, JSON.stringify(config));
} catch (err) {
console.warn('[WorkbuddyAutoCheckin] 本地缓存保存失败,使用默认配置', err);
} Defensive patterns
Strategy: fallback
Validate before calling
function isSerializable(value: unknown): boolean {
try { JSON.stringify(value); return true; } catch { return false; }
}
if (!isSerializable(config)) normalizeConfig(config); Try / catch
try {
localStorage.setItem(CONFIG_KEY, JSON.stringify(config));
} catch (err) {
console.warn('[WorkbuddyAutoCheckin] 本地缓存保存失败:', err);
// fall through: Rust-side config remains authoritative
} Prevention
- Always treat localStorage config as a cache, Rust side as source of truth
- Validate config shape before caching
- Free quota by pruning legacy cache keys
- Fall back to defaults/cache when the write fails
When it happens
Trigger: localStorage.setItem throws because the serialized config exceeds quota, storage is disabled/private-mode, or a JSON.stringify circular-structure error occurs on a malformed config object.
Common situations: localStorage nearly full from other keys; app opened in private browsing; config accidentally containing non-serializable values after a schema change.
Related errors
- [AccountStore] 本地缓存空间不足,已自动清理账号缓存并回退为仅内存态。
- [TraeAutoCheckin] 保存自动签到日志失败:
- [AccountStore] 清理超限缓存失败:
- [AccountStore] 写入持久化数据失败: ${name}
- Failed to save active page to localStorage:
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/27e63c6b29188704.
Report an issue: GitHub.