{"record":{"id":"c4222df5df6b1fdb","repo":"nikivdev/code","slug":"failed-to-create-private-repo","errorCode":null,"errorMessage":"failed to create private repo {}","messagePattern":"failed to create private repo (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/deps.rs","lineNumber":1430,"sourceCode":"    if let Some(origin_remote) = origin_remote {\n        if origin_remote.contains(&format!(\"github.com:{}/\", gh_user))\n            || origin_remote.contains(&format!(\"github.com/{}/\", gh_user))\n        {\n            return Ok(());\n        }\n    }\n\n    let private_repo = format!(\"{}/{}\", gh_user, repo_ref.repo);\n    let private_url = format!(\"git@github.com:{}.git\", private_repo);\n\n    if !gh_repo_exists(&private_repo)? {\n        println!(\"Creating private repo: {}\", private_repo);\n        let status = Command::new(\"gh\")\n            .args([\"repo\", \"create\", &private_repo, \"--private\"])\n            .status()\n            .context(\"failed to create private repo\")?;\n        if !status.success() {\n            bail!(\"failed to create private repo {}\", private_repo);\n        }\n    }\n\n    set_origin_remote(repo_dir, &private_url)?;\n    let upstream_remote = git_remote_get(repo_dir, \"upstream\")?;\n    if upstream_remote.is_none() {\n        configure_upstream(repo_dir, origin_url)?;\n    } else if upstream_remote.as_deref() != Some(origin_url) {\n        println!(\n            \"⚠ upstream already set to {} (expected {})\",\n            upstream_remote.unwrap_or_default(),\n            origin_url\n        );\n    }\n    println!(\"✓ origin -> {}\", private_repo);\n\n    Ok(())\n}","sourceCodeStart":1412,"sourceCodeEnd":1448,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/deps.rs#L1412-L1448","documentation":"Raised while forking/provisioning a private mirror (src/deps.rs:1430). There are two failure layers: a `.context` on the `gh repo create ... --private` subprocess spawn, and this bail when `gh` runs but exits non-zero. Either way, the private GitHub repo was not created, so the subsequent `set_origin_remote` never runs.","triggerScenarios":"Calling the private-mirror creation flow when the `gh` CLI is not installed (spawn context error) or `gh repo create` fails with a non-zero status: unauthenticated session, missing `repo` scope, name already taken, or org policy blocking private repo creation.","commonSituations":"`gh auth login` never run or token expired, token lacking scopes, creating under an org that restricts repo creation, GitHub API rate limits, or `gh` not installed at all.","solutions":["Run `gh auth status` and re-authenticate (`gh auth login`) ensuring the repo scope","Run the exact `gh repo create <name> --private` command manually to see the API error","Install/upgrade the GitHub CLI if missing or outdated","Choose a different repo name if the target already exists, or ask an org admin for creation rights"],"exampleFix":"// before\ngh auth status   # not logged in\nerror: failed to create private repo acme/foo-mirror\n// after\ngh auth login && gh repo create acme/foo-mirror --private\n# then rerun the f command","handlingStrategy":"retry","validationCode":"let gh = std::process::Command::new(\"gh\").args([\"auth\", \"status\"]).status();\nif !gh.map(|s| s.success()).unwrap_or(false) {\n    anyhow::bail!(\"gh CLI missing or unauthenticated; run gh auth login first\");\n}","typeGuard":"fn gh_ready() -> bool {\n    std::process::Command::new(\"gh\").args([\"auth\", \"status\"])\n        .status().map(|s| s.success()).unwrap_or(false)\n}","tryCatchPattern":"match create_private_mirror(repo) {\n    Err(e) if e.to_string().contains(\"failed to create private repo\") => {\n        eprintln!(\"gh auth expired or repo exists; fix and retry once\");\n        gh_auth_login()?;\n        create_private_mirror(repo)\n    }\n    other => other,\n}","preventionTips":["Run `gh auth status` (repo scope) before mirror operations","Check the target repo name doesn't already exist on GitHub","Confirm org policies allow private repo creation","Keep the GitHub CLI installed and updated"],"tags":["github","gh-cli","subprocess","auth"],"backgroundTag":"gh-cli-auth-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}