nikivdev/code · error
typesense collection create failed ({})
Error message
typesense collection create failed ({}) What it means
If the collection check found the collection missing (404), typesense_ensure_collection POSTs a schema to /collections to create it. A non-success create response bails with 'typesense collection create failed (<status>)'.
Source
Thrown at src/install.rs:746
let schema = serde_json::json!({
"name": config.collection,
"fields": [
{ "name": "id", "type": "string" },
{ "name": "pkg_path", "type": "string" },
{ "name": "description", "type": "string", "optional": true },
{ "name": "version", "type": "string", "optional": true }
],
"default_sorting_field": "pkg_path"
});
let mut create_req = client.post(&create_url).json(&schema);
if !config.api_key.is_empty() {
create_req = create_req.header("X-TYPESENSE-API-KEY", &config.api_key);
}
let resp = create_req
.send()
.context("failed to create typesense collection")?;
if !resp.status().is_success() {
bail!("typesense collection create failed ({})", resp.status());
}
Ok(())
}
fn typesense_import(config: &TypesenseConfig, entries: Vec<FloxDisplayEntry>) -> Result<()> {
let client = Client::builder()
.timeout(std::time::Duration::from_secs(20))
.build()?;
let base = config.url.trim_end_matches('/');
let url = format!(
"{}/collections/{}/documents/import?action=upsert",
base, config.collection
);
let mut body = String::new();
for entry in entries {
let doc = serde_json::json!({
"id": entry.pkg_path,
"pkg_path": entry.pkg_path,View on GitHub (pinned to a747e741ae)
Solutions
- Check status: 401/403 -> use a key with collection-create rights; 409 -> treat as exists and retry the flow
- Verify the schema matches the deployed Typesense version's field requirements
- Serialize/lock run_index so only one process creates the collection
- Curl POST /collections with the same schema to see the detailed error body
Example fix
// before
bail!("typesense collection create failed ({})", resp.status());
// after (tolerate concurrent create)
if resp.status() != StatusCode::CONFLICT {
bail!("typesense collection create failed ({})", resp.status());
} Defensive patterns
Strategy: retry
Validate before calling
// preflight: key must have write access
let resp = client.get(format!("{}/keys", base))
.header("X-TYPESENSE-API-KEY", &api_key)
.send().await?;
if !resp.status().is_success() {
bail!("api key lacks admin/write scope for collection creation");
} Try / catch
match run_index() {
Err(e) if e.to_string().contains("typesense collection create failed") => {
// 409 usually means a concurrent run created it — safe to proceed
eprintln!("Create failed ({}); if 409, collection likely already exists", e);
}
other => other?,
} Prevention
- Use a key with collection-create (admin) scope for run_index
- Serialize run_index across processes to avoid create races
- Match the collection schema to your Typesense version
When it happens
Trigger: Collection does not exist and the create POST fails: 401/403 (key lacks write access), 409 (race — another process created it concurrently), or 400 (schema rejected by the Typesense version).
Common situations: API key is read-only; two run_index runs racing to create the same collection; Typesense version with different schema field requirements.
Related errors
- typesense returned {}
- typesense collection check failed ({})
- typesense import failed ({})
- device auth start failed: HTTP {}
- device auth poll failed: HTTP {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/1b42d0999495237c.
Report an issue: GitHub.