{"record":{"id":"58d3ef34bea62a24","repo":"BigPizzaV3/CodexPlusPlus","slug":"error-settings-json-codex","errorCode":null,"errorMessage":"切换供应商失败：{error}；同时回滚配置失败：settings.json={}，Codex 实时文件={}","messagePattern":"切换供应商失败：(.+?)；同时回滚配置失败：settings\\.json=(.+?)，Codex 实时文件=(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/codex-plus-core/src/relay_switch.rs","lineNumber":55,"sourceCode":"\n    store\n        .save(&selected_settings)\n        .context(\"保存供应商设置失败\")?;\n    let selected_settings = store.load().context(\"读取供应商设置失败\")?;\n\n    match apply_selected_relay_profile(home, &selected_settings) {\n        Ok(result) => {\n            crate::codex_app_state::sync_app_state_after_provider_switch_nonfatal(\n                home,\n                \"relay_switch.after\",\n            );\n            Ok(result)\n        }\n        Err(error) => {\n            let settings_restore_error = store.save(&original_settings).err();\n            let live_restore_error = live_snapshot.restore(home).err();\n            if settings_restore_error.is_some() || live_restore_error.is_some() {\n                anyhow::bail!(\n                    \"切换供应商失败：{error}；同时回滚配置失败：settings.json={}，Codex 实时文件={}\",\n                    settings_restore_error\n                        .map(|error| error.to_string())\n                        .unwrap_or_else(|| \"ok\".to_string()),\n                    live_restore_error\n                        .map(|error| error.to_string())\n                        .unwrap_or_else(|| \"ok\".to_string())\n                );\n            }\n            Err(error)\n        }\n    }\n}\n\n#[derive(Debug, Clone)]\nstruct LiveFilesSnapshot {\n    config: Option<Vec<u8>>,\n    auth: Option<Vec<u8>>,","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/relay_switch.rs#L37-L73","documentation":"When switching provider profiles fails, switch_relay_profile_in_home attempts to roll back settings.json and the Codex live files (config.toml / auth.json) from snapshots taken before the switch. If either rollback itself errors, the original error is wrapped with the rollback failures so the user knows the system may be in a partially-restored state.","triggerScenarios":"Any failure inside switch_relay_profile_in_home (write failure, status-check failure, etc.) where store.save(&original_settings) or live_snapshot.restore(home) also returns Err — the combined error is raised with both messages.","commonSituations":"Disk full or permission problems preventing both the switch and the restore; config.toml/auth.json locked by another process during rollback; snapshot restore failing because live files were deleted mid-switch; underlying switch error like invalid TOML compounded by an unwritable settings.json.","solutions":["Read the {error} prefix first — fix the root switch failure (e.g. permissions, invalid config)","Manually restore: check codex_app_state snapshot dirs (relay_switch.before) and settings backups","Ensure ~/.codex and the settings store are writable and not locked by other processes","Retry the switch after restoring a consistent state; free disk space if writes failed"],"exampleFix":"// before: no guard — rollback errors surface as this combined message\nswitch_relay_profile_in_home(home, settings, id)\n// after: pre-check writability and validate config before switching\nensure_writable(home)?;\nvalidate_profile(&settings)?;\nswitch_relay_profile_in_home(home, settings, id)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await switchProfile(settings, prevId);\n} catch (e) {\n  if (String(e).includes('同时回滚配置失败')) {\n    // partial state: inspect relay_switch.before snapshot and settings backup, restore manually\n    await restoreFromSnapshot(home, 'relay_switch.before');\n  } else { throw e; }\n}","preventionTips":["Ensure ~/.codex and the settings store are writable before switching","Close other processes holding config.toml/auth.json locks during switches","Take an external backup of settings.json and live files before automating switches","Fix the root error shown before the '；' separator first"],"tags":["rollback","config","state-corruption"],"backgroundTag":"rollback-failed","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}