{"record":{"id":"389886170d06e333","repo":"jlcodes99/cockpit-tools","slug":"error-389886","errorCode":null,"errorMessage":"加载诊断配置失败:","messagePattern":"加载诊断配置失败:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/pages/SettingsPage.tsx","lineNumber":1926,"sourceCode":"    try {\n      const status = await invoke<GrokCliStatus>('grok_update_cli_runtime_config', {\n        grokCliPath: grokCliPath.trim() || null,\n      });\n      setGrokCliStatus(status);\n      setGrokCliPath(status.configuredPath || '');\n    } catch (error) {\n      setGrokCliStatusError(String(error));\n    } finally {\n      setGrokCliSaving(false);\n    }\n  };\n\n  const loadDiagnosticsConfig = async () => {\n    try {\n      const config = await invoke<DiagnosticsConfig>('get_diagnostics_config');\n      setErrorReportingEnabled(config.errorReportingEnabled);\n    } catch (err) {\n      console.warn('加载诊断配置失败:', err);\n    }\n  };\n\n  const handleErrorReportingEnabledChange = async (enabled: boolean) => {\n    const previous = errorReportingEnabled;\n    setErrorReportingEnabled(enabled);\n    setErrorReportingSaving(true);\n    try {\n      await invoke('save_diagnostics_config', {\n        errorReportingEnabled: enabled,\n        errorReportingDebug: false,\n      });\n    } catch (err) {\n      setErrorReportingEnabled(previous);\n      console.error('保存诊断配置失败:', err);\n    } finally {\n      setErrorReportingSaving(false);\n    }","sourceCodeStart":1908,"sourceCodeEnd":1944,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/pages/SettingsPage.tsx#L1908-L1944","documentation":"The settings controller loads the diagnostics config from the Rust backend via `invoke<DiagnosticsConfig>('get_diagnostics_config')`. If the command rejects (missing command, serialization mismatch, backend panic) the failure is logged with this Chinese message and error reporting stays at its default state.","triggerScenarios":"`invoke('get_diagnostics_config')` rejects: the command is not registered in the Tauri builder, the returned struct fails to deserialize into DiagnosticsConfig, or the backend errors reading its config store.","commonSituations":"Frontend/backend version skew after an upgrade (command renamed or payload field added as non-optional); corrupted backend config file; running a web build without the Tauri backend.","solutions":["Confirm `get_diagnostics_config` is registered via `invoke_handler` in the Rust app and the name matches exactly.","Compare the returned JSON shape with the DiagnosticsConfig type; make new backend fields optional in the TS type or defaults in Rust.","Check the backend config storage is readable/valid; reset diagnostics config if corrupted.","Inspect the logged `err` (Tauri includes the command's error string) to pinpoint registration vs serialization."],"exampleFix":"// before\nconst config = await invoke<DiagnosticsConfig>('get_diagnostics_config');\n// after\nlet config: DiagnosticsConfig;\ntry {\n  config = await invoke<DiagnosticsConfig>('get_diagnostics_config');\n} catch {\n  config = { errorReportingEnabled: true }; // safe default\n}","handlingStrategy":"try-catch","validationCode":"const registered = await invoke<boolean>('has_command', { name: 'get_diagnostics_config' }).catch(() => false);\nif (!registered) useDefaultDiagnosticsConfig();","typeGuard":"function isDiagnosticsConfig(v: unknown): v is DiagnosticsConfig {\n  return typeof v === 'object' && v !== null && typeof (v as any).errorReportingEnabled === 'boolean';\n}","tryCatchPattern":"try {\n  const config = await invoke<DiagnosticsConfig>('get_diagnostics_config');\n  if (isDiagnosticsConfig(config)) setErrorReportingEnabled(config.errorReportingEnabled);\n  else setErrorReportingEnabled(true); // default\n} catch (err) {\n  console.warn('加载诊断配置失败:', err);\n  setErrorReportingEnabled(true); // safe default on load failure\n}","preventionTips":["Keep backend command names and TS types in sync; treat new fields as optional","Apply a safe default when the config can't be loaded","Verify invoke_handler registration when adding new commands","Validate the deserialized shape before trusting it"],"tags":["tauri","ipc","invoke","serialization"],"backgroundTag":"tauri-command-invocation-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"}