{"record":{"id":"8db606bbba816920","repo":"jlcodes99/cockpit-tools","slug":"error-8db606","errorCode":null,"errorMessage":"实例绑定账号注入失败: {}","messagePattern":"实例绑定账号注入失败: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/commands/github_copilot_instance.rs","lineNumber":49,"sourceCode":"        .ok_or_else(|| format!(\"绑定账号不存在: {}\", bind_id))?;\n    modules::logger::log_info(&format!(\n        \"实例启动检测到绑定账号，准备注入: bind_account_id={}, login={}, user_data_dir={}\",\n        bind_id, account.github_login, user_data_dir\n    ));\n\n    // Ensure DB is writable before injection.\n    modules::process::close_vscode(&[user_data_dir.to_string()], 20)?;\n\n    modules::logger::log_info(\"正在向实例目录注入 GitHub Copilot Token...\");\n    let github_id = account.github_id.to_string();\n    modules::vscode_inject::inject_copilot_token_for_user_data_dir(\n        user_data_dir,\n        &account.github_login,\n        &account.github_access_token,\n        Some(&github_id),\n    )\n    .map_err(|e| {\n        modules::logger::log_error(&format!(\"实例绑定账号注入失败: {}\", e));\n        format!(\"按绑定账号注入实例失败（{}）: {}\", account.github_login, e)\n    })?;\n\n    modules::logger::log_info(&format!(\"实例绑定账号注入完成: {}\", account.github_login));\n\n    Ok(())\n}\n\n#[tauri::command]\npub async fn github_copilot_get_instance_defaults(\n) -> Result<modules::instance::InstanceDefaults, String> {\n    modules::github_copilot_instance::get_instance_defaults()\n}\n\n#[tauri::command]\npub async fn github_copilot_list_instances() -> Result<Vec<InstanceProfileView>, String> {\n    let store = modules::github_copilot_instance::load_instance_store()?;\n    let default_dir = modules::github_copilot_instance::get_default_vscode_user_data_dir()?;","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src-tauri/src/commands/github_copilot_instance.rs#L31-L67","documentation":"When starting a Cursor instance that has a bound GitHub Copilot account, the app injects the account's github_login and github_access_token into the instance's user_data_dir before launch. This error is logged and converted into a user-facing message when that injection step fails, and the instance start is aborted via `?`.","triggerScenarios":"The injection helper called with (user_data_dir, account.github_login, account.github_access_token, Some(github_id)) returned Err — e.g. user_data_dir cannot be created/written, auth JSON write failed, or the bound account record has a missing/invalid token.","commonSituations":"Disk permission problems or read-only profile directory; the bound account's GitHub token was revoked/expired so injection validation fails; concurrent instance start racing on the same user_data_dir; the binding referencing a deleted GitHub account.","solutions":["Re-bind the GitHub Copilot account to the instance (re-authenticate) so a fresh token is injected","Check that the instance user_data_dir exists and is writable by the app","Verify the bound account still exists and its github_access_token is valid on GitHub","Retry starting the instance — transient file locks from a previous run can block injection"],"exampleFix":"// before\n.inject_bound_account(&user_data_dir, &account.github_login, &account.github_access_token, Some(&github_id))\n.map_err(|e| {\n    modules::logger::log_error(&format!(\"实例绑定账号注入失败: {}\", e));\n    format!(\"按绑定账号注入实例失败（{}）: {}\", account.github_login, e)\n})?;\n// after\n.inject_bound_account(&user_data_dir, &account.github_login, &account.github_access_token, Some(&github_id))\n.map_err(|e| {\n    modules::logger::log_error(&format!(\"实例绑定账号注入失败: {}\", e));\n    // fall back to starting without pre-injection so the user can log in manually in the instance\n    modules::logger::log_warn(\"回退为不注入绑定账号启动实例\");\n    e\n});","handlingStrategy":"try-catch","validationCode":"// before starting the instance, verify the binding is still usable\nif !account_binding_exists(&github_id) {\n    return Err(format!(\"实例 {} 未绑定有效的 GitHub 账号\", github_id));\n}\nif account.github_access_token.is_empty() {\n    return Err(format!(\"绑定账号 {} 的令牌缺失，请重新绑定\", account.github_login));\n}\nif !is_dir_writable(&user_data_dir) {\n    return Err(format!(\"实例目录不可写: {}\", user_data_dir));\n}","typeGuard":null,"tryCatchPattern":"match inject_bound_account(&user_data_dir, &account.github_login, &account.github_access_token, Some(&github_id)) {\n    Ok(()) => { /* proceed with start */ }\n    Err(e) => {\n        log_error(&format!(\"实例绑定账号注入失败: {}\", e));\n        // offer fallback: start without injection so the user can sign in manually\n        return Err(format!(\"按绑定账号注入实例失败（{}）: {}\", account.github_login, e));\n    }\n}","preventionTips":["Re-authenticate bound GitHub accounts whose tokens were revoked/expired","Ensure the instance user_data_dir is writable (permissions, disk space)","Avoid starting two instances sharing the same user_data_dir simultaneously","Rebind the account if the binding points to a deleted GitHub account"],"tags":["github-copilot","cursor","account-injection","token"],"backgroundTag":"account-injection-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"}