{"record":{"id":"12717ee1a2afd817","repo":"janhq/jan","slug":"string-e","errorCode":null,"errorMessage":"${String(e)}","messagePattern":"\\$\\{String\\(e\\)\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"extensions/llamacpp-extension/src/index.ts","lineNumber":3729,"sourceCode":"          }\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 invoke<SessionInfo | null>(\n        'plugin:llamacpp|find_session_by_model',\n        { modelId }\n      )\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 invoke<SessionInfo>('plugin:llamacpp|ensure_session_ready', {\n      modelId,\n      isEmbedding: false,\n    })\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 = {","sourceCodeStart":3711,"sourceCodeEnd":3747,"githubUrl":"https://github.com/janhq/jan/blob/fad3f12a147d138388a66f0d92a02b2675f65294/extensions/llamacpp-extension/src/index.ts#L3711-L3747","documentation":"Thrown by findSessionByModel() when the underlying Tauri/Rust invoke('plugin:llamacpp|find_session_by_model') rejects. This private helper is called by load() and unload() to query the router's session table; any IPC/plugin-layer failure (plugin not registered, Rust panic, router plugin not initialized, IPC serialization error) is caught, logged, and re-thrown as a plain Error wrapping String(e).","triggerScenarios":"The llamacpp plugin (Rust side) failed to load or is not registered. The router plugin's IPC channel is broken after a crash. The Rust handler panicked on a malformed modelId. Tauri IPC serialization mismatch (struct shape changed across versions). The plugin sidecar process died mid-call.","commonSituations":"Extension/plugin version skew (TS calls an IPC command the installed Rust plugin does not expose). Router plugin crashed and the IPC layer returns an error object whose String form is '[object Object]' or a JSON blob. Development hot-reload left the plugin in a half-initialized state.","solutions":["Check logger.error output for the raw rejection value (logged just before the throw).","Restart the app/router so the plugin re-initializes and re-registers its IPC commands.","Ensure the extension (TS) and the plugin (Rust) are from the same release - mismatched IPC command names are the usual cause.","If String(e) is '[object Object]', the catch loses detail; inspect e with util.inspect/JSON.stringify in dev to recover the real cause."],"exampleFix":"// before\nconst s = await provider.findSessionByModel('qwen') // throws opaque String(e)\n// after - improve error shape at the boundary\nclass IpcError extends Error {\n  constructor(public cause: unknown) { super(typeof cause === 'string' ? cause : JSON.stringify(cause)) }\n}\n// in findSessionByModel catch:\n//   throw new IpcError(e)  // preserves object shape for callers\n// caller:\ntry { await provider.load('qwen') }\ncatch (e) { console.error('plugin ipc failed:', e); /* restart router */ }","handlingStrategy":"try-catch","validationCode":"// Caller can't validate plugin internals; best pre-check is router liveness.\nif (!(await provider.getRouterInfo())) throw new Error('router not alive - find_session_by_model will fail')","typeGuard":"// The catch loses detail; improve it at the source instead.\nfunction asMessage(e: unknown): string {\n  return e instanceof Error ? e.message : typeof e === 'string' ? e : JSON.stringify(e)\n}","tryCatchPattern":"try { await provider.load(modelId) }\ncatch (e) {\n  // findSessionByModel wraps; treat plugin-IPC errors as 'restart needed'\n  logger.error('plugin ipc failed, restarting router:', e)\n  await provider.startRouter()\n  await provider.load(modelId)\n}","preventionTips":["Keep extension (TS) and plugin (Rust) versions in sync so IPC command names match.","Restart the router/app after plugin crashes before retrying IPC calls.","Patch the catch in findSessionByModel to preserve object shape (avoid String(e) on objects)."],"tags":["ipc","plugin","tauri","session","rust","load"],"backgroundTag":null,"analyzedSha":"fad3f12a147d138388a66f0d92a02b2675f65294","analyzedAt":"2026-08-12T20:33:47.516Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}