nikivdev/code · error

typesense import failed ({})

Error message

typesense import failed ({})

What it means

typesense_import bulk-imports documents into the Typesense collection via POST. A non-success response bails with 'typesense import failed (<status>)'. Note Typesense can return 200 with per-document import errors in the body — those are not caught here.

Source

Thrown at src/install.rs:777

    );
    let mut body = String::new();
    for entry in entries {
        let doc = serde_json::json!({
            "id": entry.pkg_path,
            "pkg_path": entry.pkg_path,
            "description": entry.description,
            "version": entry.version
        });
        body.push_str(&doc.to_string());
        body.push('\n');
    }
    let mut request = client.post(&url).body(body);
    if !config.api_key.is_empty() {
        request = request.header("X-TYPESENSE-API-KEY", &config.api_key);
    }
    let resp = request.send().context("failed to import into typesense")?;
    if !resp.status().is_success() {
        bail!("typesense import failed ({})", resp.status());
    }
    Ok(())
}

fn load_index_queries(query: Option<String>, path: Option<PathBuf>) -> Result<Vec<String>> {
    let mut out = Vec::new();
    if let Some(path) = path {
        let content = fs::read_to_string(&path)
            .with_context(|| format!("failed to read {}", path.display()))?;
        for line in content.lines() {
            let trimmed = line.trim();
            if trimmed.is_empty() || trimmed.starts_with('#') {
                continue;
            }
            out.push(trimmed.to_string());
        }
    }
    if let Some(query) = query {

View on GitHub (pinned to a747e741ae)

Solutions

  1. Ensure typesense_ensure_collection succeeded before importing
  2. Check the status: 404 -> create collection; 401/403 -> fix api_key; 413 -> chunk the import into smaller batches
  3. Inspect Typesense server logs/disk space for 5xx responses
  4. Also check the response body even on 200 — Typesense reports per-doc import errors there
Defensive patterns

Strategy: retry

Validate before calling

// ensure collection exists before importing
let head = client.get(format!("{}/collections/{}", base, collection))
    .header("X-TYPESENSE-API-KEY", &api_key)
    .send().await?;
if head.status().as_u16() == 404 {
    bail!("run ensure_collection before import");
}

Try / catch

match run_index() {
    Err(e) if e.to_string().contains("typesense import failed") => {
        eprintln!("Import rejected ({}); retry with smaller batch after checking collection/key", e);
    }
    other => other?,
}

Prevention

When it happens

Trigger: The import POST returns 4xx/5xx during run_index: bad API key (401), missing collection (404 — ensure_collection not run or failed), payload too large (413), or server errors.

Common situations: Running import before the collection exists; importing very large batches hitting request size limits; read-only API key; Typesense disk-full (503).

Related errors


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