{"record":{"id":"8165d98bed37f924","repo":"chroma-core/chroma","slug":"error-calling-chroma-embedding-api-error","errorCode":null,"errorMessage":"Error calling Chroma Embedding API: ${error}","messagePattern":"Error calling Chroma Embedding API: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/ai-embeddings/chroma-cloud-qwen/src/index.ts","lineNumber":141,"sourceCode":"    };\n\n    try {\n      const response = await fetch(this.url, {\n        method: \"POST\",\n        headers: this.headers,\n        body: JSON.stringify(snakeCase(body)),\n      });\n\n      const data = (await response.json()) as ChromaCloudEmbeddingsResponse;\n      if (!data || !data.embeddings) {\n        throw new Error(\"Failed to generate embeddings.\");\n      }\n      return data.embeddings;\n    } catch (error) {\n      if (error instanceof Error) {\n        throw new Error(`Error calling Chroma Embedding API: ${error.message}`);\n      } else {\n        throw new Error(`Error calling Chroma Embedding API: ${error}`);\n      }\n    }\n  }\n\n  public async generateForQueries(texts: string[]): Promise<number[][]> {\n    if (texts.length === 0) {\n      return [];\n    }\n\n    let instruction = \"\";\n    if (this.task && this.task in this.instructions) {\n      instruction =\n        this.instructions[this.task][ChromaCloudQwenEmbeddingTarget.QUERY];\n    }\n\n    const body: ChromaCloudEmbeddingRequest = {\n      texts,\n      instructions: instruction,","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/ai-embeddings/chroma-cloud-qwen/src/index.ts#L123-L159","documentation":"Fallback branch of the catch in ChromaCloudQwenEmbeddingFunction.generate(): a non-Error value was thrown inside the request block (string, number, object) and is stringified into \"Error calling Chroma Embedding API: <value>\". This is uncommon in Node (fetch and json() reject with Error objects) but can occur with interceptors, mocks, or runtimes that throw primitives.","triggerScenarios":"Test frameworks or fetch mocks that reject with plain strings/objects; custom fetch polyfills throwing non-Error values; exotic runtimes whose fetch rejects with primitive values.","commonSituations":"Unit tests mocking global fetch with jest.fn().mockRejectedValue(\"boom\"); older fetch shims; SDK instrumentation wrapping fetch.","solutions":["Make your fetch mocks reject with Error objects (mockRejectedValue(new Error('boom'))).","Inspect the stringified value in the message to find what non-Error throw occurred.","If a custom fetch polyfill is in play, prefer the global fetch implementation."],"exampleFix":"// before (test mock)\nglobal.fetch = jest.fn().mockRejectedValue(\"network boom\");\n\n// after\nglobal.fetch = jest.fn().mockRejectedValue(new Error(\"network boom\"));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await ef.generate(texts);\n} catch (e) {\n  // Message embeds a non-Error throw; surface it verbatim for diagnosis\n  console.error(\"Embedding failed with non-Error throw:\", (e as Error).message);\n  throw e;\n}","preventionTips":["Make fetch mocks reject with Error instances in tests.","Avoid fetch polyfills that throw primitives.","Log the full wrapped message; the suffix identifies the foreign throw."],"tags":["embeddings","cloud-api","qwen","error-wrapping","testing"],"backgroundTag":"embedding-api-request-failed","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}