{"record":{"id":"3402f21e68e2fa09","repo":"jlcodes99/cockpit-tools","slug":"workbuddyautocheckin-rust","errorCode":null,"errorMessage":"[WorkbuddyAutoCheckin] 从 Rust 端获取配置失败，使用本地缓存或默认值:","messagePattern":"\\[WorkbuddyAutoCheckin\\] 从 Rust 端获取配置失败，使用本地缓存或默认值:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/services/workbuddyAutoCheckinService.ts","lineNumber":73,"sourceCode":"    return;\n  }\n  try {\n    localStorage.setItem(CONFIG_KEY, JSON.stringify(config));\n    if (emitChange) {\n      window.dispatchEvent(new Event(WORKBUDDY_AUTO_CHECKIN_CONFIG_CHANGED_EVENT));\n    }\n  } catch (err) {\n    console.warn('[WorkbuddyAutoCheckin] 本地缓存保存失败:', err);\n  }\n}\n\nexport async function getWorkbuddyAutoCheckinConfigAsync(): Promise<WorkbuddyAutoCheckinConfig> {\n  try {\n    const config = await invoke<WorkbuddyAutoCheckinConfig>('get_workbuddy_auto_checkin_config');\n    cacheConfigLocally(config);\n    return config;\n  } catch (err) {\n    console.warn('[WorkbuddyAutoCheckin] 从 Rust 端获取配置失败，使用本地缓存或默认值:', err);\n    return getWorkbuddyAutoCheckinConfig();\n  }\n}\n\nexport function getWorkbuddyAutoCheckinConfig(): WorkbuddyAutoCheckinConfig {\n  if (cachedConfig) {\n    return cachedConfig;\n  }\n  if (typeof window === 'undefined') {\n    return DEFAULT_WORKBUDDY_AUTO_CHECKIN_CONFIG;\n  }\n  try {\n    const raw = localStorage.getItem(CONFIG_KEY);\n    if (!raw) {\n      return DEFAULT_WORKBUDDY_AUTO_CHECKIN_CONFIG;\n    }\n    const parsed = JSON.parse(raw);\n    const config: WorkbuddyAutoCheckinConfig = {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/services/workbuddyAutoCheckinService.ts#L55-L91","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the invoke command name matches the registered Rust handler (check generate_handler! list)","Rebuild/restart the app so frontend and backend versions align","Inspect the Rust log for a deserialization panic and fix the config file","Confirm the fallback path returns sane defaults — the code already does"],"exampleFix":"// before\nconst config = await invoke<WorkbuddyAutoCheckinConfig>('get_workbuddy_auto_checkin_config');\n// after\nconst config = await invoke<WorkbuddyAutoCheckinConfig>('get_workbuddy_auto_checkin_config').catch(async (err) => {\n  console.warn('[WorkbuddyAutoCheckin] 从 Rust 端获取配置失败:', err);\n  return getWorkbuddyAutoCheckinConfig();\n});","handlingStrategy":"fallback","validationCode":"const hasTauri = typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;\nconst config = hasTauri\n  ? await getWorkbuddyAutoCheckinConfigAsync()\n  : getWorkbuddyAutoCheckinConfig();","typeGuard":"function hasTauriBackend(w: unknown): w is { __TAURI_INTERNALS__: unknown } {\n  return typeof w === 'object' && w !== null && '__TAURI_INTERNALS__' in w;\n}","tryCatchPattern":"try {\n  const config = await invoke<WorkbuddyAutoCheckinConfig>('get_workbuddy_auto_checkin_config');\n  cacheConfigLocally(config);\n  return config;\n} catch (err) {\n  console.warn('[WorkbuddyAutoCheckin] 从 Rust 端获取配置失败，使用本地缓存或默认值:', err);\n  return getWorkbuddyAutoCheckinConfig();\n}","preventionTips":["Confirm the invoke command name matches the registered Rust handler","Guard for non-Tauri (web) builds before invoking","Keep the local-cache/default fallback path healthy","Pin frontend and backend versions together to avoid command drift"],"tags":["tauri","invoke","fallback"],"backgroundTag":"tauri-command-invoke-failed","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}