jlcodes99/cockpit-tools · error

实例绑定账号注入失败: {}

Error message

实例绑定账号注入失败: {}

What it means

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 `?`.

Source

Thrown at src-tauri/src/commands/github_copilot_instance.rs:49

        .ok_or_else(|| format!("绑定账号不存在: {}", bind_id))?;
    modules::logger::log_info(&format!(
        "实例启动检测到绑定账号,准备注入: bind_account_id={}, login={}, user_data_dir={}",
        bind_id, account.github_login, user_data_dir
    ));

    // Ensure DB is writable before injection.
    modules::process::close_vscode(&[user_data_dir.to_string()], 20)?;

    modules::logger::log_info("正在向实例目录注入 GitHub Copilot Token...");
    let github_id = account.github_id.to_string();
    modules::vscode_inject::inject_copilot_token_for_user_data_dir(
        user_data_dir,
        &account.github_login,
        &account.github_access_token,
        Some(&github_id),
    )
    .map_err(|e| {
        modules::logger::log_error(&format!("实例绑定账号注入失败: {}", e));
        format!("按绑定账号注入实例失败({}): {}", account.github_login, e)
    })?;

    modules::logger::log_info(&format!("实例绑定账号注入完成: {}", account.github_login));

    Ok(())
}

#[tauri::command]
pub async fn github_copilot_get_instance_defaults(
) -> Result<modules::instance::InstanceDefaults, String> {
    modules::github_copilot_instance::get_instance_defaults()
}

#[tauri::command]
pub async fn github_copilot_list_instances() -> Result<Vec<InstanceProfileView>, String> {
    let store = modules::github_copilot_instance::load_instance_store()?;
    let default_dir = modules::github_copilot_instance::get_default_vscode_user_data_dir()?;

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Re-bind the GitHub Copilot account to the instance (re-authenticate) so a fresh token is injected
  2. Check that the instance user_data_dir exists and is writable by the app
  3. Verify the bound account still exists and its github_access_token is valid on GitHub
  4. Retry starting the instance — transient file locks from a previous run can block injection

Example fix

// before
.inject_bound_account(&user_data_dir, &account.github_login, &account.github_access_token, Some(&github_id))
.map_err(|e| {
    modules::logger::log_error(&format!("实例绑定账号注入失败: {}", e));
    format!("按绑定账号注入实例失败({}): {}", account.github_login, e)
})?;
// after
.inject_bound_account(&user_data_dir, &account.github_login, &account.github_access_token, Some(&github_id))
.map_err(|e| {
    modules::logger::log_error(&format!("实例绑定账号注入失败: {}", e));
    // fall back to starting without pre-injection so the user can log in manually in the instance
    modules::logger::log_warn("回退为不注入绑定账号启动实例");
    e
});
Defensive patterns

Strategy: try-catch

Validate before calling

// before starting the instance, verify the binding is still usable
if !account_binding_exists(&github_id) {
    return Err(format!("实例 {} 未绑定有效的 GitHub 账号", github_id));
}
if account.github_access_token.is_empty() {
    return Err(format!("绑定账号 {} 的令牌缺失,请重新绑定", account.github_login));
}
if !is_dir_writable(&user_data_dir) {
    return Err(format!("实例目录不可写: {}", user_data_dir));
}

Try / catch

match inject_bound_account(&user_data_dir, &account.github_login, &account.github_access_token, Some(&github_id)) {
    Ok(()) => { /* proceed with start */ }
    Err(e) => {
        log_error(&format!("实例绑定账号注入失败: {}", e));
        // offer fallback: start without injection so the user can sign in manually
        return Err(format!("按绑定账号注入实例失败({}): {}", account.github_login, e));
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.


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