{"record":{"id":"ac892c5802c5e9a9","repo":"nikivdev/code","slug":"typesense-collection-check-failed","errorCode":null,"errorMessage":"typesense collection check failed ({})","messagePattern":"typesense collection check failed \\((.+?)\\)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/install.rs","lineNumber":724,"sourceCode":"\nfn typesense_ensure_collection(config: &TypesenseConfig) -> Result<()> {\n    let client = Client::builder()\n        .timeout(std::time::Duration::from_secs(5))\n        .build()?;\n    let base = config.url.trim_end_matches('/');\n    let get_url = format!(\"{}/collections/{}\", base, config.collection);\n    let mut request = client.get(&get_url);\n    if !config.api_key.is_empty() {\n        request = request.header(\"X-TYPESENSE-API-KEY\", &config.api_key);\n    }\n    let resp = request\n        .send()\n        .context(\"failed to check typesense collection\")?;\n    if resp.status().is_success() {\n        return Ok(());\n    }\n    if resp.status().as_u16() != 404 {\n        bail!(\"typesense collection check failed ({})\", resp.status());\n    }\n\n    let create_url = format!(\"{}/collections\", base);\n    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","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/install.rs#L706-L742","documentation":"typesense_ensure_collection first GETs the collection endpoint to see if it exists. Any non-success status other than 404 (which means 'create it') is treated as an unexpected failure and bails with 'typesense collection check failed (<status>)'.","triggerScenarios":"The collection-existence GET returns 401/403 (bad API key), 5xx (server error), or any non-404 error status during run_index.","commonSituations":"Wrong API key lacking read access; Typesense unreachable/misconfigured and a proxy returns 502; Typesense version returning an unexpected status for missing collections (e.g. 400 instead of 404).","solutions":["Check the status code: 401/403 -> fix api_key; 5xx -> inspect Typesense server logs","Verify the base URL/collection name in TypesenseConfig","Curl GET {base}/collections/{collection} with the key to reproduce","Upgrade/downgrade Typesense if it returns non-404 for missing collections"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// preflight collection check with the same key\nlet resp = reqwest::Client::new()\n    .get(format!(\"{}/collections/{}\", base, collection))\n    .header(\"X-TYPESENSE-API-KEY\", &api_key)\n    .send().await?;\nprintln!(\"collection check status: {}\", resp.status());","typeGuard":null,"tryCatchPattern":"match run_index() {\n    Err(e) if e.to_string().contains(\"typesense collection check failed\") => {\n        eprintln!(\"Cannot verify collection: {} — check key/server\", e);\n    }\n    other => other?,\n}","preventionTips":["Use an API key with read access to collections","Confirm base URL/port before running run_index","Verify your Typesense version returns 404 (not another status) for missing collections"],"tags":["http","typesense","configuration"],"backgroundTag":"upstream-http-error","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}