{"record":{"id":"e579d830413cf882","repo":"Mintplex-Labs/anything-llm","slug":"e-message-e579d8","errorCode":null,"errorMessage":"e.message","messagePattern":"e\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/koboldCPP/index.js","lineNumber":140,"sourceCode":"      ...formatChatHistory(chatHistory, this.#generateContent),\n      {\n        role: \"user\",\n        content: this.#generateContent({ userPrompt, attachments }),\n      },\n    ];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions\n        .create({\n          model: this.model,\n          messages,\n          temperature,\n          max_tokens: this.maxTokens,\n        })\n        .catch((e) => {\n          throw new Error(e.message);\n        })\n    );\n\n    if (\n      !result.output.hasOwnProperty(\"choices\") ||\n      result.output.choices.length === 0\n    )\n      return null;\n\n    const promptTokens = LLMPerformanceMonitor.countTokens(messages);\n    const completionTokens = LLMPerformanceMonitor.countTokens([\n      { content: result.output.choices[0].message.content },\n    ]);\n\n    return {\n      textResponse: result.output.choices[0].message.content,\n      metrics: {\n        prompt_tokens: promptTokens,","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/koboldCPP/index.js#L122-L158","documentation":"Not a distinct error condition but a catch-and-rethrow wrapper around the OpenAI SDK call inside KoboldCPP's getChatCompletion. The `.catch((e) => { throw new Error(e.message); })` strips the original SDK error type, status code, headers, and cause, leaving only the human-readable message string. Any network, auth, rate-limit, or model-not-found failure from the KoboldCPP OpenAI-compatible endpoint surfaces through this wrapper.","triggerScenarios":"Calling `koboldcppProvider.getChatCompletion(messages, { temperature })` when the underlying KoboldCPP server is unreachable, returns a non-200, rejects the API key, reports the model as not loaded, or times out. The OpenAI SDK's `chat.completions.create()` promise rejects, and the catch re-wraps the message.","commonSituations":"KoboldCPP server was stopped or crashed after AnythingLLM started. The base path URL is wrong or missing the /v1 suffix. The model was unloaded from KoboldCPP between configuration and chat. Rate limiting or GPU OOM on the KoboldCPP host produces a 5xx that the SDK surfaces as an error message.","solutions":["Check that the KoboldCPP server is running and reachable at KOBOLD_CPP_BASE_PATH using curl or a browser.","Inspect the raw error message for status codes or model-not-found text — the wrapper preserves the message but discards structured data.","Verify the model named in KOBOLD_CPP_MODEL_PREF is currently loaded in the KoboldCPP instance.","If the wrapper itself is the problem (you need status codes), refactor the catch to re-throw the original error instead of new Error(e.message)."],"exampleFix":"// before — original error type and status are lost\n.catch((e) => {\n  throw new Error(e.message);\n})\n\n// after — preserve the original error for upstream handling\n.catch((e) => {\n  throw e;\n})","handlingStrategy":"try-catch","validationCode":"async function checkKoboldCPPHealth(basePath) {\n  const res = await fetch(`${basePath}/models`);\n  if (!res.ok) throw new Error(`KoboldCPP at ${basePath} returned ${res.status}`);\n  return true;\n}\n\n// Optional pre-flight before calling getChatCompletion:\nawait checkKoboldCPPHealth(process.env.KOBOLD_CPP_BASE_PATH);","typeGuard":null,"tryCatchPattern":"try {\n  const result = await koboldcppProvider.getChatCompletion(messages, { temperature: 0.7 });\n} catch (e) {\n  // e.message contains the original SDK message but type/status are lost.\n  // Check for common patterns:\n  if (e.message.includes('ECONNREFUSED') || e.message.includes('fetch failed')) {\n    console.error('KoboldCPP server is not reachable at', process.env.KOBOLD_CPP_BASE_PATH);\n  } else if (e.message.includes('model') && e.message.includes('not')) {\n    console.error('Model not loaded on KoboldCPP server:', process.env.KOBOLD_CPP_MODEL_PREF);\n  } else {\n    console.error('KoboldCPP chat completion failed:', e.message);\n  }\n}","preventionTips":["Implement a health-check endpoint that pings KoboldCPP's /v1/models before forwarding chat requests.","Monitor KoboldCPP server process health externally and restart if it crashes.","Consider refactoring the catch to preserve the original SDK error for better upstream error classification."],"tags":["koboldcpp","api-error","openai-sdk","error-wrapping","runtime"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}