nikivdev/code · error

gitedit publish failed: HTTP {}

Error message

gitedit publish failed: HTTP {}

What it means

run_gitedit POSTs the project payload to the gitedit API via reqwest; if the HTTP response status is not a success (2xx), it bails with `gitedit publish failed: HTTP <status>`. The status code is the server's verdict — 4xx indicates a client-side problem (bad token, missing fields) and 5xx a server-side problem.

Source

Thrown at src/publish.rs:531

        repo_snapshot: Some(snapshot),
    };

    let base_url = gitedit_api_url(&repo_root);
    let api_url = format!("{}/api/mirrors/sync", base_url.trim_end_matches('/'));
    let view_url = format!("{}/{}/{}", base_url.trim_end_matches('/'), owner, repo_name);
    let token = gitedit_token(&repo_root);

    let client = Client::builder()
        .timeout(Duration::from_secs(30))
        .build()
        .context("failed to build HTTP client")?;
    let mut request = client.post(&api_url).json(&payload);
    if let Some(token) = token {
        request = request.bearer_auth(token);
    }
    let response = request.send().context("failed to publish to gitedit")?;
    if !response.status().is_success() {
        bail!("gitedit publish failed: HTTP {}", response.status());
    }

    println!();
    println!("✓ Published to {}", view_url);
    Ok(())
}

fn resolve_repo_name(opts: &PublishOpts, fallback: &str) -> Result<String> {
    let name = if let Some(name) = opts.name.clone() {
        name
    } else if opts.yes {
        fallback.to_string()
    } else {
        print!("Repository name [{}]: ", fallback);
        io::stdout().flush()?;
        let mut input = String::new();
        io::stdin().read_line(&mut input)?;
        let input = input.trim();

View on GitHub (pinned to a747e741ae)

Solutions

  1. Check the HTTP status in the message: 401/403 → refresh or set the gitedit token; 404 → verify the API URL; 5xx → retry later or check server health
  2. Verify the gitedit token configured for this environment is current
  3. Run with dry-run/inspect the payload if available to catch 422 validation issues (owner, slug, snapshot fields)
  4. Retry on 502/503/504 — transient server errors resolve on their own
Defensive patterns

Strategy: retry

Validate before calling

let token = std::env::var("GITEDIT_TOKEN").ok();
if token.as_deref().map(str::is_empty) != Some(false) {
    eprintln!("no gitedit token configured; set it before publishing");
    std::process::exit(1);
}
// optional preflight
let health = reqwest::blocking::get(format!("{api_url}/health"))?;
if !health.status().is_success() { eprintln!("gitedit API unhealthy: {}", health.status()); }

Try / catch

if let Err(e) = run_gitedit(&opts) {
    let msg = e.to_string();
    if let Some(status) = msg.strip_prefix("gitedit publish failed: HTTP ") {
        match status {
            "401" | "403" => eprintln!("refresh gitedit token"),
            "502" | "503" | "504" => eprintln!("transient server error; retry"),
            _ => eprintln!("server rejected publish: {}", status),
        }
    }
}

Prevention

When it happens

Trigger: POST to the gitedit API URL returns non-2xx: 401/403 for a missing or invalid bearer token, 404 for a wrong api_url, 409/422 for validation conflicts (e.g. name/owner collisions), 5xx for server errors.

Common situations: Expired or revoked gitedit token in the environment; pointing at a staging API URL that moved; publishing a slug that already exists with conflicting metadata; gitedit server downtime.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/8ae2b9976b39aa42. Report an issue: GitHub.