{"record":{"id":"7b26914daac96c28","repo":"jlcodes99/cockpit-tools","slug":"datatransfer","errorCode":null,"errorMessage":"[DataTransfer] 配置导入失败后回滚应用自启动状态失败: {}","messagePattern":"\\[DataTransfer\\] 配置导入失败后回滚应用自启动状态失败: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src-tauri/src/commands/data_transfer.rs","lineNumber":138,"sourceCode":"            || current.report_port != next_config.report_port\n            || current.report_token != next_config.report_token;\n        language_changed = current.language != next_config.language;\n        #[cfg(target_os = \"macos\")]\n        {\n            hide_dock_icon_changed = current.hide_dock_icon != next_config.hide_dock_icon;\n            tray_icon_style_changed = current.tray_icon_style != next_config.tray_icon_style;\n        }\n        *current = next_config.clone();\n        Ok(())\n    });\n    let next_config = match patch_result {\n        Ok(config) => config,\n        Err(error) => {\n            if app_auto_launch_changed {\n                if let Err(rollback_error) =\n                    apply_app_auto_launch_enabled(&app, previous_auto_launch)\n                {\n                    modules::logger::log_error(&format!(\n                        \"[DataTransfer] 配置导入失败后回滚应用自启动状态失败: {}\",\n                        rollback_error\n                    ));\n                }\n            }\n            return Err(error);\n        }\n    };\n\n    if let Err(err) = modules::floating_card_window::apply_floating_card_always_on_top(&app) {\n        modules::logger::log_warn(&format!(\"[DataTransfer] 应用悬浮卡片置顶状态失败: {}\", err));\n    }\n\n    #[cfg(target_os = \"macos\")]\n    if hide_dock_icon_changed {\n        crate::apply_macos_activation_policy(&app);\n    }\n","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src-tauri/src/commands/data_transfer.rs#L120-L156","documentation":"During user-config import (data_transfer_apply_user_config), if the import itself fails while the app auto-launch setting had already been changed, the code attempts to roll back the auto-launch setting to its previous value. This error is logged when that rollback also fails, meaning the system is left with an auto-launch state that differs from the user's original configuration.","triggerScenarios":"apply_user_config returned Err while app_auto_launch_changed was true, and the compensating apply_app_auto_launch_enabled(&app, previous_auto_launch) call also returned Err — e.g. OS-level autostart registration failed (missing desktop entry / registry write failure / permissions).","commonSituations":"Restoring a config on a platform where autostart registration is broken (Linux desktop-entry issues, sandboxed/Flatpak environments); read-only or permission-restricted autostart location; the import failed due to a malformed config file while autostart had already been toggled off.","solutions":["Manually re-check and reset the app's 'launch at startup' toggle in settings to restore the previous state","Re-run the config import after fixing the underlying import failure (the wrapped `error` in the returned Err tells you why import failed)","Check OS autostart configuration (systemd user services / autostart .desktop file / registry) for permission problems","Avoid importing configs that toggle auto-launch across machines with different OS environments without verifying autostart works"],"exampleFix":"// before\nif let Err(rollback_error) = apply_app_auto_launch_enabled(&app, previous_auto_launch) {\n    modules::logger::log_error(&format!(\"[DataTransfer] 配置导入失败后回滚应用自启动状态失败: {}\", rollback_error));\n}\nreturn Err(error);\n// after\nif let Err(rollback_error) = apply_app_auto_launch_enabled(&app, previous_auto_launch) {\n    modules::logger::log_error(&format!(\"[DataTransfer] 配置导入失败后回滚应用自启动状态失败: {}\", rollback_error));\n    // surface both failures so the user knows the auto-launch state may be inconsistent\n    return Err(format!(\"{}；此外，回滚应用自启动状态失败: {}\", error, rollback_error));\n}\nreturn Err(error);","handlingStrategy":"try-catch","validationCode":"// validate config and autostart capability BEFORE applying anything\nif let Err(e) = validate_user_config(&imported_config) {\n    return Err(format!(\"配置无效，未做任何修改: {}\", e));\n}\nif app_auto_launch_changed && !auto_launch_supported() {\n    return Err(\"当前环境不支持自启动设置，已取消导入\".to_string());\n}","typeGuard":null,"tryCatchPattern":"// apply, and on failure roll back; if rollback also fails, surface BOTH errors\nmatch apply_user_config(&config).await {\n    Ok(v) => Ok(v),\n    Err(error) => {\n        if app_auto_launch_changed {\n            if let Err(rb) = apply_app_auto_launch_enabled(&app, previous_auto_launch) {\n                return Err(format!(\"{}；且回滚自启动状态失败，请手动检查自启动设置: {}\", error, rb));\n            }\n        }\n        Err(error)\n    }\n}","preventionTips":["Validate the imported config before applying any side effects","Apply auto-launch only after the main config import succeeds (order side effects last)","Verify autostart works on the target platform (Flatpak/sandboxed environments often break it)","After a failed import, always re-check the auto-launch toggle"],"tags":["data-transfer","config-import","autostart","rollback"],"backgroundTag":"config-import-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"}