{"record":{"id":"08032ccec12d641f","repo":"nikivdev/code","slug":"failed-to-create-repository","errorCode":null,"errorMessage":"Failed to create repository","messagePattern":"Failed to create repository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/publish.rs","lineNumber":365,"sourceCode":"        \"create\".to_string(),\n        repo_name.clone(),\n        format!(\"--{}\", visibility),\n        \"--source=.\".to_string(),\n        \"--push\".to_string(),\n    ];\n\n    if let Some(desc) = opts.description {\n        args.push(\"--description\".to_string());\n        args.push(desc);\n    }\n\n    let create_result = Command::new(\"gh\")\n        .args(&args)\n        .status()\n        .context(\"failed to create repository\")?;\n\n    if !create_result.success() {\n        bail!(\"Failed to create repository\");\n    }\n\n    println!();\n    println!(\"✓ Published to https://github.com/{}\", full_name);\n\n    Ok(())\n}\n\nconst MAX_GITEDIT_FILE_BYTES: u64 = 512 * 1024;\nconst MAX_GITEDIT_TOTAL_BYTES: u64 = 8 * 1024 * 1024;\nconst MAX_GITEDIT_FILES: usize = 4000;\n\n#[derive(Serialize)]\n#[serde(rename_all = \"snake_case\")]\nstruct RepoSnapshot {\n    repo: RepoMeta,\n    tree: Vec<RepoTreeEntry>,\n    files: Vec<RepoFileEntry>,","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/publish.rs#L347-L383","documentation":"run_github creates the repository by invoking `gh repo create ...`; the command runs but exits with a non-zero status, so the tool bails with this generic failure message. The underlying cause (name conflict, auth, network) is printed by `gh` itself to stderr before this error is raised.","triggerScenarios":"`gh repo create <owner>/<name> --<visibility> ...` returns a failing exit status: repository name already exists under the owner, the token lacks `repo`/`create repo` scope, rate limiting, or network failure.","commonSituations":"Re-publishing an existing project with the same folder name; organization accounts that forbid member repo creation; expired GitHub token lacking repo scope; `gh repo create` syntax changes across gh versions.","solutions":["Read the stderr lines printed by `gh repo create` just above this error for the real cause","If the repo already exists, skip creation (the publish flow detects existing repos when it can check) or pick a new name with --name","Run `gh auth status` / `gh auth refresh -s repo` to ensure the token has repo-creation scopes","Check you can create repos manually: `gh repo create test-repo --private`","If an org policy blocks creation, create the repo on github.com first and publish with --url"],"exampleFix":"// before: failing because repo exists\nf publish --repo myapp\n// after: reuse existing repo via --url\nf publish --url git@github.com:myuser/myapp.git","handlingStrategy":"try-catch","validationCode":"let check = std::process::Command::new(\"gh\")\n    .args([\"repo\", \"view\", &format!(\"{}/{}\", owner, name), \"--json\", \"name\"])\n    .output()?;\nif check.status.success() {\n    eprintln!(\"repo already exists; skipping creation\");\n    return Ok(()); // or reuse it instead of calling create\n}","typeGuard":null,"tryCatchPattern":"match run_github(opts) {\n    Err(e) if e.to_string().contains(\"Failed to create repository\") => {\n        eprintln!(\"gh repo create failed; check stderr above — name conflict, token scope, or network\");\n    }\n    other => other?,\n}","preventionTips":["Check `gh repo view owner/name` before publishing to an existing name","Ensure the gh token has `repo` scope (`gh auth refresh -s repo`)","Prefer --url pointing at an existing repo to skip the create path entirely"],"tags":["github","gh-cli","repository-creation","shell-out"],"backgroundTag":"github-repo-creation-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}