nikivdev/code · error

{}

Error message

{}

What it means

Final bail after the OpenAI retry loop exhausts all attempts without success. It surfaces the last recorded error (`last_error`) verbatim, or a fallback string if no error was recorded — e.g. a server error (5xx) or transient network failure persisted across every retry.

Source

Thrown at src/commit.rs:12978

                    .map(|m| m.content.trim().to_string())
                    .unwrap_or_default();

                if message.is_empty() {
                    bail!("OpenAI returned empty commit message");
                }

                return Ok(trim_quotes(&message));
            }
            Err(e) => {
                last_error = Some(format!("failed to call OpenAI API: {}", e));
                if attempt < MAX_RETRIES - 1 {
                    println!("API call failed, will retry...");
                }
            }
        }
    }

    bail!(
        "{}",
        last_error.unwrap_or_else(|| "OpenAI API failed after retries".to_string())
    )
}

fn generate_commit_message_remote(
    api_url: &str,
    token: &str,
    diff: &str,
    status: &str,
    truncated: bool,
) -> Result<String> {
    let trimmed = api_url.trim().trim_end_matches('/');
    let url = format!("{}/api/ai/commit-message", trimmed);

    let client = crate::http_client::blocking_with_timeout(Duration::from_secs(
        commit_with_check_timeout_secs(),
    ))

View on GitHub (pinned to a747e741ae)

Solutions

  1. Read the embedded last_error message to identify the root cause (status code or reqwest error).
  2. Wait for OpenAI service recovery and retry (check status.openai.com).
  3. Increase retry count/backoff in the calling code for 429 rate limits.
  4. Check local network/proxy configuration blocking api.openai.com.
Defensive patterns

Strategy: retry

Validate before calling

// Check basic reachability of the OpenAI API before retrying
let reachable = reqwest::get("https://api.openai.com/v1/models").await
    .map(|r| r.status() != reqwest::StatusCode::SERVICE_UNAVAILABLE)
    .unwrap_or(false);
if !reachable { return Err(anyhow!("OpenAI API unreachable")); }

Try / catch

match result {
    Err(e) if e.to_string().contains("failed after retries") => {
        eprintln!("OpenAI unavailable after retries; using local fallback: {e}");
        fallback_to_local_message()
    }
    other => other,
}

Prevention

When it happens

Trigger: All retry attempts fail with transient (5xx/network) errors that hit the `continue` branch, or the loop finishes without ever producing a message.

Common situations: OpenAI outage or degraded service (5xx); persistent network failures (proxy, DNS); sustained rate limiting (429) across all retries.

Related errors


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