jlcodes99/cockpit-tools · warning

[WorkbuddyAutoCheckin] 从 Rust 端获取配置失败,使用本地缓存或默认值:

Error message

[WorkbuddyAutoCheckin] 从 Rust 端获取配置失败,使用本地缓存或默认值:

What it means

getWorkbuddyAutoCheckinConfigAsync fetches the config from the Rust backend via Tauri invoke('get_workbuddy_auto_checkin_config'). If the invoke rejects (backend error, command missing, app not ready), it falls back to the localStorage cache or defaults and only logs a warning.

Source

Thrown at src/services/workbuddyAutoCheckinService.ts:73

    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;
  }
  if (typeof window === 'undefined') {
    return DEFAULT_WORKBUDDY_AUTO_CHECKIN_CONFIG;
  }
  try {
    const raw = localStorage.getItem(CONFIG_KEY);
    if (!raw) {
      return DEFAULT_WORKBUDDY_AUTO_CHECKIN_CONFIG;
    }
    const parsed = JSON.parse(raw);
    const config: WorkbuddyAutoCheckinConfig = {

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Verify the invoke command name matches the registered Rust handler (check generate_handler! list)
  2. Rebuild/restart the app so frontend and backend versions align
  3. Inspect the Rust log for a deserialization panic and fix the config file
  4. Confirm the fallback path returns sane defaults — the code already does

Example fix

// before
const config = await invoke<WorkbuddyAutoCheckinConfig>('get_workbuddy_auto_checkin_config');
// after
const config = await invoke<WorkbuddyAutoCheckinConfig>('get_workbuddy_auto_checkin_config').catch(async (err) => {
  console.warn('[WorkbuddyAutoCheckin] 从 Rust 端获取配置失败:', err);
  return getWorkbuddyAutoCheckinConfig();
});
Defensive patterns

Strategy: fallback

Validate before calling

const hasTauri = typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
const config = hasTauri
  ? await getWorkbuddyAutoCheckinConfigAsync()
  : getWorkbuddyAutoCheckinConfig();

Type guard

function hasTauriBackend(w: unknown): w is { __TAURI_INTERNALS__: unknown } {
  return typeof w === 'object' && w !== null && '__TAURI_INTERNALS__' in w;
}

Try / catch

try {
  const config = await invoke<WorkbuddyAutoCheckinConfig>('get_workbuddy_auto_checkin_config');
  cacheConfigLocally(config);
  return config;
} catch (err) {
  console.warn('[WorkbuddyAutoCheckin] 从 Rust 端获取配置失败,使用本地缓存或默认值:', err);
  return getWorkbuddyAutoCheckinConfig();
}

Prevention

When it happens

Trigger: The Rust command 'get_workbuddy_auto_checkin_config' is not registered, panics, or the Tauri IPC bridge fails; also when called before the backend initializes.

Common situations: Version mismatch between frontend and bundled Rust commands (command renamed); running the web build without the Tauri backend; backend config file corrupted causing deserialize failure in Rust.

Related errors


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