{"record":{"id":"1b42d0999495237c","repo":"nikivdev/code","slug":"typesense-collection-create-failed","errorCode":null,"errorMessage":"typesense collection create failed ({})","messagePattern":"typesense collection create failed \\((.+?)\\)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/install.rs","lineNumber":746,"sourceCode":"    let schema = serde_json::json!({\n        \"name\": config.collection,\n        \"fields\": [\n            { \"name\": \"id\", \"type\": \"string\" },\n            { \"name\": \"pkg_path\", \"type\": \"string\" },\n            { \"name\": \"description\", \"type\": \"string\", \"optional\": true },\n            { \"name\": \"version\", \"type\": \"string\", \"optional\": true }\n        ],\n        \"default_sorting_field\": \"pkg_path\"\n    });\n    let mut create_req = client.post(&create_url).json(&schema);\n    if !config.api_key.is_empty() {\n        create_req = create_req.header(\"X-TYPESENSE-API-KEY\", &config.api_key);\n    }\n    let resp = create_req\n        .send()\n        .context(\"failed to create typesense collection\")?;\n    if !resp.status().is_success() {\n        bail!(\"typesense collection create failed ({})\", resp.status());\n    }\n    Ok(())\n}\n\nfn typesense_import(config: &TypesenseConfig, entries: Vec<FloxDisplayEntry>) -> Result<()> {\n    let client = Client::builder()\n        .timeout(std::time::Duration::from_secs(20))\n        .build()?;\n    let base = config.url.trim_end_matches('/');\n    let url = format!(\n        \"{}/collections/{}/documents/import?action=upsert\",\n        base, config.collection\n    );\n    let mut body = String::new();\n    for entry in entries {\n        let doc = serde_json::json!({\n            \"id\": entry.pkg_path,\n            \"pkg_path\": entry.pkg_path,","sourceCodeStart":728,"sourceCodeEnd":764,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/install.rs#L728-L764","documentation":"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>)'.","triggerScenarios":"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).","commonSituations":"API key is read-only; two run_index runs racing to create the same collection; Typesense version with different schema field requirements.","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"],"exampleFix":"// before\nbail!(\"typesense collection create failed ({})\", resp.status());\n// after (tolerate concurrent create)\nif resp.status() != StatusCode::CONFLICT {\n    bail!(\"typesense collection create failed ({})\", resp.status());\n}","handlingStrategy":"retry","validationCode":"// preflight: key must have write access\nlet resp = client.get(format!(\"{}/keys\", base))\n    .header(\"X-TYPESENSE-API-KEY\", &api_key)\n    .send().await?;\nif !resp.status().is_success() {\n    bail!(\"api key lacks admin/write scope for collection creation\");\n}","typeGuard":null,"tryCatchPattern":"match run_index() {\n    Err(e) if e.to_string().contains(\"typesense collection create failed\") => {\n        // 409 usually means a concurrent run created it — safe to proceed\n        eprintln!(\"Create failed ({}); if 409, collection likely already exists\", e);\n    }\n    other => other?,\n}","preventionTips":["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"],"tags":["http","typesense","permissions"],"backgroundTag":"upstream-http-error","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}