{"record":{"id":"2c13b999bcdcf041","repo":"jlcodes99/cockpit-tools","slug":"systemconfig","errorCode":null,"errorMessage":"[SystemConfig] 配置保存失败后回滚应用自启动状态失败: {}","messagePattern":"\\[SystemConfig\\] 配置保存失败后回滚应用自启动状态失败: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src-tauri/src/commands/system_network_general.rs","lineNumber":576,"sourceCode":"            hide_dock_icon_changed = previous_hide_dock_icon != current.hide_dock_icon;\n            tray_icon_style_changed = previous_tray_icon_style != current.tray_icon_style;\n            menu_bar_quota_changed = previous_menu_bar_quota\n                != (\n                    current.menu_bar_quota_enabled,\n                    current.menu_bar_show_account_prefix,\n                    current.menu_bar_quota_platform.clone(),\n                );\n        }\n        Ok(())\n    });\n\n    let new_config = match patch_result {\n        Ok(config) => config,\n        Err(error) => {\n            if auto_launch_os_changed {\n                if let Some(previous) = previous_auto_launch {\n                    if let Err(rollback_error) = apply_app_auto_launch_enabled(&app, previous) {\n                        modules::logger::log_error(&format!(\n                            \"[SystemConfig] 配置保存失败后回滚应用自启动状态失败: {}\",\n                            rollback_error\n                        ));\n                    }\n                }\n            }\n            return Err(error);\n        }\n    };\n\n    if token_keeper_enabled_changed {\n        modules::provider_token_keeper::notify_config_changed(\n            app.clone(),\n            new_config.token_keeper_enabled,\n        );\n    }\n\n    if auto_import_from_local_enabled_changed {","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src-tauri/src/commands/system_network_general.rs#L558-L594","documentation":"In patch_general_config (src-tauri/src/commands/system_network_general.rs), if saving the general config fails after the OS auto-launch toggle was already applied, the code attempts to roll back auto-launch to its previous state; if that rollback itself fails it logs this message. The original config-save error is still the primary error; this is a secondary, logged-only failure.","triggerScenarios":"patch_user_config/patch_result returned Err while auto_launch_os_changed was true, AND apply_app_auto_launch_enabled(&app, previous) also returned Err during rollback (e.g. autostart backend API failure).","commonSituations":"The autostart plugin cannot modify the platform's launch registry/agent (permissions, AppArmor/Sandbox restrictions); the app handle's autostart state is out of sync; the config failure was itself caused by the same underlying permission problem.","solutions":["Fix the primary config-save error first (check the original `error` from patch_result) — often the same permission problem causes both.","Verify the app has permission to modify OS auto-launch entries (Login Items on macOS, registry/Startup folder on Windows, autostart .desktop on Linux).","Manually toggle the app's launch-at-login setting in OS settings to resynchronize state.","Retry the config save after resolving permissions; the rollback message is informational and logged, not returned to the caller."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify autostart is controllable before toggling it in the same patch\nconst canToggle = await invoke('can_apply_auto_launch').catch(() => false);\nif (!canToggle) throw new Error('当前环境无法修改开机自启动');","typeGuard":null,"tryCatchPattern":"const result = await invoke('patch_general_config', { patch });\n// rollback failures are logged, not returned; check app logs for the rollback tag:\nconst logs = await readAppLogs();\nif (logs.some(l => l.includes('回滚应用自启动状态失败'))) {\n  await invoke('resync_auto_launch_state');\n}","preventionTips":["Apply autostart toggles only after config save succeeds (two-phase commit)","Test autostart permission changes on all supported OSes","Expose a 'resync autostart' action for desynchronized state","Check OS Login Items / Startup permissions in packaging docs"],"tags":["tauri","autostart","rollback","config"],"backgroundTag":"rollback-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"}