{"record":{"id":"9dadc7516ff0c6df","repo":"chroma-core/chroma","slug":"error-calling-jina-ai-api-error","errorCode":null,"errorMessage":"Error calling Jina AI API: ${error}","messagePattern":"Error calling Jina AI API: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/embeddings/JinaEmbeddingFunction.ts","lineNumber":134,"sourceCode":"        method: \"POST\",\n        headers: this.headers,\n        body: JSON.stringify(json_body),\n      });\n\n      const data = (await response.json()) as { data: any[]; detail: string };\n      if (!data || !data.data) {\n        throw new Error(data.detail);\n      }\n\n      const embeddings: any[] = data.data;\n      const sortedEmbeddings = embeddings.sort((a, b) => a.index - b.index);\n\n      return sortedEmbeddings.map((result) => result.embedding);\n    } catch (error) {\n      if (error instanceof Error) {\n        throw new Error(`Error calling Jina AI API: ${error.message}`);\n      } else {\n        throw new Error(`Error calling Jina AI API: ${error}`);\n      }\n    }\n  }\n\n  buildFromConfig(config: StoredConfig): JinaEmbeddingFunction {\n    return new JinaEmbeddingFunction({\n      model_name: config.model_name,\n      api_key_env_var: config.api_key_env_var,\n      task: config.task,\n      late_chunking: config.late_chunking,\n      truncate: config.truncate,\n      dimensions: config.dimensions,\n      embedding_type: config.embedding_type,\n      normalized: config.normalized,\n    });\n  }\n\n  getConfig(): StoredConfig {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/JinaEmbeddingFunction.ts#L116-L152","documentation":"The rarely-taken else branch of the same catch: it fires only when the caught value is not an Error instance — e.g. a rejected promise carrying a plain string, number, or custom object from somewhere in the Jina request path. In practice almost all Node fetch/JSON failures are Errors, so this is essentially a formatting fallback that stringifies whatever was thrown.","triggerScenarios":"A dependency, runtime shim, or test double inside the request path rejecting with a non-Error value (throw \"string\", Promise.reject(42), custom object without Error prototype).","commonSituations":"Exotic runtimes/bundlers that alter rejection shapes; unit tests with mocks rejecting strings; essentially never seen in normal Node usage.","solutions":["Log the raw value — the template stringifies it, so printing the error reveals the thrower","Search the dependency chain for non-Error throw sites (throw \"...\" or reject(\"...\") ) and fix or shim them to throw proper Errors","Update/replace the offending package if it comes from a third-party dependency"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const vecs = await ef.generate(texts);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e); // normalize non-Error throwables\n  if (msg.startsWith(\"Error calling Jina AI API:\")) {\n    // inspect the suffix; a stringified non-Error usually points at a mock or shim\n  }\n  throw e;\n}","preventionTips":["Enable @typescript-eslint/only-throw-error so your own code never throws non-Error values","Reject with Error objects in test doubles/mocks, not plain strings","Upgrade third-party shims that reject with non-Error values"],"tags":["jina","error-wrapping","embeddings","non-error-throw"],"backgroundTag":"upstream-api-error","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}