{"record":{"id":"082a886158797c46","repo":"janhq/jan","slug":"string-e-index","errorCode":null,"errorMessage":"String(e)","messagePattern":"String\\(e\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extensions/llamacpp-extension/src/index.ts","lineNumber":2491,"sourceCode":"            logger.error('Error parsing JSON from stream or server error:', e)\n            // re‑throw so the async iterator terminates with an error\n            throw e\n          }\n        }\n      }\n    } finally {\n      reader.releaseLock()\n    }\n  }\n\n  private async findSessionByModel(\n    modelId: string\n  ): Promise<SessionInfo | null> {\n    try {\n      return await pluginFindSessionByModel(modelId)\n    } catch (e) {\n      logger.error(e)\n      throw new Error(String(e))\n    }\n  }\n\n  private async ensureHealthySession(modelId: string): Promise<SessionInfo> {\n    return pluginEnsureSessionReady(modelId, false)\n  }\n\n  override async chat(\n    opts: chatCompletionRequest,\n    abortController?: AbortController\n  ): Promise<chatCompletion | AsyncIterable<chatCompletionChunk>> {\n    const sessionInfo = await this.ensureHealthySession(opts.model)\n    const baseUrl = `http://localhost:${sessionInfo.port}/v1`\n    const url = `${baseUrl}/chat/completions`\n    const headers = {\n      'Content-Type': 'application/json',\n      'Authorization': `Bearer ${sessionInfo.api_key}`,\n    }","sourceCodeStart":2473,"sourceCodeEnd":2509,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/extensions/llamacpp-extension/src/index.ts#L2473-L2509","documentation":"Wraps any failure from pluginFindSessionByModel (looking up the inference session for a model) into a generic Error with the stringified original error. The extension logs the original then rethrows so callers see a consistent error surface from getSessionByModel.","triggerScenarios":"pluginFindSessionByModel throws — e.g. the plugin/session registry rejects because no session exists for the modelId, the engine subprocess is down, or the IPC call to the engine fails.","commonSituations":"Querying a session for a model that was never loaded; the llamacpp engine process crashed or restarted; modelId casing/ID mismatch versus what was registered.","solutions":["Verify the modelId is loaded (check getLoadedModels) before looking up its session.","Check the engine process is running and the engine preset is fresh.","Reload the model to recreate the session, then retry the lookup.","Compare the thrown string against the logged original error for the true root cause."],"exampleFix":"// before\n} catch (e) {\n  logger.error(e)\n  throw new Error(String(e))\n}\n// after\n} catch (e) {\n  logger.error(e)\n  throw new Error(`Failed to find session for model ${modelId}: ${e instanceof Error ? e.message : String(e)}`)\n}","handlingStrategy":"try-catch","validationCode":"const loaded = await getLoadedModels()\nif (!loaded.includes(modelId)) throw new Error(`Model ${modelId} is not loaded`)","typeGuard":"null","tryCatchPattern":"try {\n  const session = await getSessionByModel(modelId)\n} catch (e) {\n  logger.warn(`No session for ${modelId}: ${e}`)\n  const session = await loadModelThenGetSession(modelId) // fallback: load first\n}","preventionTips":["Always load the model before querying its session.","Use the model IDs returned by listModels rather than hand-typed strings.","Treat missing-session errors as 'load model first', not fatal.","Check the log output for the underlying plugin error — the rethrown message is just String(e)."],"tags":["session","llamacpp","error-wrapping"],"backgroundTag":"record-not-found","analyzedSha":"7205d770c1e097c3daf35a911176410e93bc5564","analyzedAt":"2026-09-17T14:27:30.100Z","contentChangedAt":"2026-09-17T14:27:30.100Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}