{"record":{"id":"d28cb2c1a6ff4df2","repo":"chroma-core/chroma","slug":"precondition-failed","errorCode":null,"errorMessage":"Precondition Failed","messagePattern":"Precondition Failed","errorType":"http","errorClass":"ChromaClientError","httpStatus":412,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/chroma-fetch.ts","lineNumber":105,"sourceCode":"      if (\n        conflictBody.error === \"ConditionalWriteConflictError\" ||\n        conflictBody.message === \"conditional write conflict\"\n      ) {\n        throw new ChromaConditionalWriteConflictError(\n          conflictBody.message || \"conditional write conflict\",\n        );\n      }\n      throw new ChromaUniqueError(\n        conflictBody.message || \"The resource already exists\",\n      );\n    case 412:\n      const preconditionBody = await getErrorBody(response);\n      if (preconditionBody.error === \"StaleReadError\") {\n        throw new ChromaStaleReadError(\n          preconditionBody.message || \"stale read\",\n        );\n      }\n      throw new ChromaClientError(\n        preconditionBody.message || \"Precondition Failed\",\n      );\n    case 422:\n      try {\n        const body = await response.json();\n        if (\n          body &&\n          body.message &&\n          (body.message.startsWith(\"Quota exceeded\") ||\n            body.message.startsWith(\"Billing limit exceeded\"))\n        ) {\n          throw new ChromaQuotaExceededError(body?.message);\n        }\n        throw new ChromaClientError(body?.message || \"Unprocessable Entity\");\n      } catch (error) {\n        if (\n          error instanceof ChromaQuotaExceededError ||\n          error instanceof ChromaClientError","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/chroma-fetch.ts#L87-L123","documentation":"Thrown by chromaFetch (chroma-fetch.ts:105) as a generic ChromaClientError when the server returns 412 but the body is not a StaleReadError. HTTP 412 means a precondition the client asserted in request headers (e.g. If-Match / version-match style checks) failed: the resource state does not satisfy the condition the client demanded.","triggerScenarios":"A request with a version/precondition header whose expectation no longer holds — e.g. delete or update with if-version equal to an outdated collection version, or gateway-injected precondition checks failing.","commonSituations":"Optimistic version checks on collection modifications racing with other writers; proxies/load balancers adding If-* header checks; custom server middleware enforcing preconditions.","solutions":["Inspect the server's message in the error body to identify which precondition failed.","Re-read the current resource state/version and reissue the request with a fresh precondition or none.","If a proxy injects precondition headers, remove or fix that configuration.","Wrap the call in a retry loop that refreshes the version on each 412."],"exampleFix":"// before\nawait collection.delete({ ids }, /* ifVersion */ staleVersion); // 412 Precondition Failed\n\n// after\nconst current = await client.getCollection({ name: collection.name }); // refresh version\nawait current.delete({ ids }); // or pass current.version as the precondition","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await collection.delete(args);\n} catch (e) {\n  if (e instanceof ChromaClientError && /Precondition/.test(e.message)) {\n    // re-read current version, then re-issue with fresh precondition or without one\n  }\n  throw e;\n}","preventionTips":["Keep preconditions short-lived: read the version immediately before the guarded write.","Refresh resource state after any 412 before retrying.","Only attach version preconditions when you actually need lost-update detection."],"tags":["http-412","precondition","versioning","concurrency"],"backgroundTag":"precondition-failed","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}