jlcodes99/cockpit-tools · info

[WorkbuddyAutoCheckin] 清理废弃的自动签到日志缓存失败:

Error message

[WorkbuddyAutoCheckin] 清理废弃的自动签到日志缓存失败:

What it means

clearLegacyWorkbuddyAutoCheckinLogs removes an obsolete WebView-era logs key from localStorage. Failures are caught and warned because leftover legacy data is harmless; the cleanup is purely hygienic.

Source

Thrown at src/services/workbuddyAutoCheckinService.ts:42

const LEGACY_LOGS_KEY = 'agtools.workbuddy.auto_checkin_logs';
export const WORKBUDDY_AUTO_CHECKIN_CONFIG_CHANGED_EVENT = 'workbuddy-auto-checkin-config-changed';
const AUTO_CHECKIN_RETRY_DELAY_MS = 5 * 60 * 1000;
const AUTO_CHECKIN_IDLE_RECHECK_DELAY_MS = 60 * 60 * 1000;

export type WorkbuddyAutoCheckinCycleResult = 'disabled' | 'waiting' | 'completed' | 'retry';

export function clearLegacyWorkbuddyAutoCheckinLogs(): void {
  if (typeof window === 'undefined') {
    return;
  }

  try {
    if (localStorage.getItem(LEGACY_LOGS_KEY) !== null) {
      localStorage.removeItem(LEGACY_LOGS_KEY);
      console.info('[WorkbuddyAutoCheckin] 已清理废弃的 WebView 自动签到日志缓存');
    }
  } catch (err) {
    console.warn('[WorkbuddyAutoCheckin] 清理废弃的自动签到日志缓存失败:', err);
  }
}

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));

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Verify localStorage is accessible before attempting cleanup
  2. Skip the cleanup when storage is unavailable — legacy data is inert
  3. Manually clear site data in the browser to remove the legacy key
Defensive patterns

Strategy: try-catch

Validate before calling

function storageAvailable(): boolean {
  try { const k = '__t__'; localStorage.setItem(k, k); localStorage.removeItem(k); return true; }
  catch { return false; }
}
if (storageAvailable()) clearLegacyWorkbuddyAutoCheckinLogs();

Try / catch

try {
  if (localStorage.getItem(LEGACY_LOGS_KEY) !== null) localStorage.removeItem(LEGACY_LOGS_KEY);
} catch (err) {
  console.warn('[WorkbuddyAutoCheckin] 清理废弃的自动签到日志缓存失败:', err);
}

Prevention

When it happens

Trigger: localStorage.removeItem or getItem throws — storage disabled, quota error surfaced on remove, or access denied in private/policy-restricted browsing contexts.

Common situations: Upgrading from a WebView build where localStorage is blocked by the embedder; hardened browser settings with storage APIs disabled.

Related errors


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