jlcodes99/cockpit-tools · warning

加载诊断配置失败:

Error message

加载诊断配置失败:

What it means

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.

Source

Thrown at src/pages/SettingsPage.tsx:1926

    try {
      const status = await invoke<GrokCliStatus>('grok_update_cli_runtime_config', {
        grokCliPath: grokCliPath.trim() || null,
      });
      setGrokCliStatus(status);
      setGrokCliPath(status.configuredPath || '');
    } catch (error) {
      setGrokCliStatusError(String(error));
    } finally {
      setGrokCliSaving(false);
    }
  };

  const loadDiagnosticsConfig = async () => {
    try {
      const config = await invoke<DiagnosticsConfig>('get_diagnostics_config');
      setErrorReportingEnabled(config.errorReportingEnabled);
    } catch (err) {
      console.warn('加载诊断配置失败:', err);
    }
  };

  const handleErrorReportingEnabledChange = async (enabled: boolean) => {
    const previous = errorReportingEnabled;
    setErrorReportingEnabled(enabled);
    setErrorReportingSaving(true);
    try {
      await invoke('save_diagnostics_config', {
        errorReportingEnabled: enabled,
        errorReportingDebug: false,
      });
    } catch (err) {
      setErrorReportingEnabled(previous);
      console.error('保存诊断配置失败:', err);
    } finally {
      setErrorReportingSaving(false);
    }

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Confirm `get_diagnostics_config` is registered via `invoke_handler` in the Rust app and the name matches exactly.
  2. Compare the returned JSON shape with the DiagnosticsConfig type; make new backend fields optional in the TS type or defaults in Rust.
  3. Check the backend config storage is readable/valid; reset diagnostics config if corrupted.
  4. Inspect the logged `err` (Tauri includes the command's error string) to pinpoint registration vs serialization.

Example fix

// before
const config = await invoke<DiagnosticsConfig>('get_diagnostics_config');
// after
let config: DiagnosticsConfig;
try {
  config = await invoke<DiagnosticsConfig>('get_diagnostics_config');
} catch {
  config = { errorReportingEnabled: true }; // safe default
}
Defensive patterns

Strategy: try-catch

Validate before calling

const registered = await invoke<boolean>('has_command', { name: 'get_diagnostics_config' }).catch(() => false);
if (!registered) useDefaultDiagnosticsConfig();

Type guard

function isDiagnosticsConfig(v: unknown): v is DiagnosticsConfig {
  return typeof v === 'object' && v !== null && typeof (v as any).errorReportingEnabled === 'boolean';
}

Try / catch

try {
  const config = await invoke<DiagnosticsConfig>('get_diagnostics_config');
  if (isDiagnosticsConfig(config)) setErrorReportingEnabled(config.errorReportingEnabled);
  else setErrorReportingEnabled(true); // default
} catch (err) {
  console.warn('加载诊断配置失败:', err);
  setErrorReportingEnabled(true); // safe default on load failure
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Related errors


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