jlcodes99/cockpit-tools · info

Failed to apply startup page preference:

Error message

Failed to apply startup page preference:

What it means

MainApp applies the persisted startup_page configuration via normalizeStartupPagePreference and setPage; if reading or processing the preference throws, this warning is logged and the app falls back to its default page. It is non-fatal by design: a bad preference should never block app startup.

Source

Thrown at src/App.tsx:820

      console.warn('Failed to save active page to localStorage:', e);
    }
  }, [page]);

  // 冷启动:若设置了固定启动页,则覆盖 localStorage 中的上次页面
  useEffect(() => {
    let disposed = false;
    const applyStartupPagePreference = async () => {
      try {
        const config = await invoke<{ startup_page?: string }>('get_general_config');
        if (disposed) {
          return;
        }
        const preferred = normalizeStartupPagePreference(config.startup_page);
        if (preferred !== 'last') {
          setPage(preferred);
        }
      } catch (error) {
        console.warn('Failed to apply startup page preference:', error);
      }
    };
    void applyStartupPagePreference();
    return () => {
      disposed = true;
    };
  }, []);

  // 冷启动:根据用户配置自动恢复 Codex 代理接管状态
  useEffect(() => {
    void useCodexAccountStore.getState().restoreActiveTakeoverIfNeeded();
  }, []);

  // 主窗口切到某平台页(如 Grok)时,同步悬浮窗/菜单栏当前平台,避免一直停在默认 antigravity
  useEffect(() => {
    const platformId = resolvePlatformIdFromPage(page);
    if (!platformId) {
      return;

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Log the caught error's contents to see whether it is an IO error or a parse error
  2. Validate/normalize startup_page against the known enum before use; normalizeStartupPagePreference should already coerce unknown values — check its input isn't undefined/null in an unexpected shape
  3. Repair or reset the config file / persisted store holding startup_page
  4. Ensure the config backend (Tauri store plugin) is initialized before this effect runs

Example fix

// before
const preferred = normalizeStartupPagePreference(config.startup_page);
if (preferred !== 'last') setPage(preferred);
// after
const preferred = normalizeStartupPagePreference(config?.startup_page);
if (preferred && preferred !== 'last') setPage(preferred);
Defensive patterns

Strategy: validation

Validate before calling

const STARTUP_PAGES = ['home', 'accounts', 'settings', 'last'] as const;
type StartupPage = typeof STARTUP_PAGES[number];
function isValidStartupPage(v: unknown): v is StartupPage {
  return typeof v === 'string' && (STARTUP_PAGES as readonly string[]).includes(v);
}

Type guard

function isStartupPageConfig(v: unknown): v is { startup_page: StartupPage } {
  return isPlainObject(v) && isValidStartupPage((v as { startup_page?: unknown }).startup_page);
}

Try / catch

try {
  const config = await loadConfig();
  const preferred = normalizeStartupPagePreference(config?.startup_page);
  if (preferred !== 'last') setPage(preferred);
} catch (error) {
  console.warn('Failed to apply startup page preference:', error);
  // keep default page
}

Prevention

When it happens

Trigger: The async config load rejects (Tauri store/backend read failure, config file corrupt or missing), or config.startup_page contains a value normalizeStartupPagePreference doesn't recognize and downstream code assumptions break.

Common situations: Hand-edited or migrated config files with an unexpected startup_page value; permission errors reading the config dir; backend store plugin not ready at first render.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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