{"record":{"id":"d7a335d6ed058243","repo":"gitbutlerapp/gitbutler","slug":"failed-to-communicate-with-lm-studio-server-err","errorCode":null,"errorMessage":"Failed to communicate with LM Studio server: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to communicate with LM Studio server: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/desktop/src/lib/ai/lmStudioClient.ts","lineNumber":119,"sourceCode":"\t\t\t\t\t\t\t\t\tresult += token;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\tconsole.warn(\"Error parsing streaming JSON\", e);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\t// Handle non-streaming response\n\t\t\telse {\n\t\t\t\tconst json = await response.json();\n\t\t\t\treturn json.choices[0]?.message?.content || \"\";\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Error calling LM Studio API:\", error);\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to communicate with LM Studio server: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t}\n}\n","sourceCodeStart":101,"sourceCodeEnd":125,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/apps/desktop/src/lib/ai/lmStudioClient.ts#L101-L125","documentation":"The catch-all wrapper in evaluate(): any error thrown inside the try block (validation, network failure, JSON parse, errors 0-2) is rethrown with the prefix 'Failed to communicate with LM Studio server:' and the original message appended. It signals the LM Studio call failed, with the cause nested in the message.","triggerScenarios":"Any failure inside evaluate(): unreachable server / fetch TypeError, non-JSON response body passed to response.json(), or any of the earlier explicit throws.","commonSituations":"LM Studio server not started (ECONNREFUSED); wrong port; CORS blocking the request in the webview; server returning HTML error pages instead of JSON.","solutions":["Read the wrapped original message to identify the root cause.","Verify LM Studio's local server is running and reachable (curl http://localhost:1234/v1/models).","Check the endpoint URL and port in the app's AI settings.","If in a browser context, confirm CORS is not blocking the local server."],"exampleFix":"// before\nconst client = new LMStudioClient('http://localhost:9999/v1', model);\n// after\nconst client = new LMStudioClient('http://localhost:1234/v1', model); // server actually running here","handlingStrategy":"try-catch","validationCode":"// reachability pre-check\nconst res = await fetch(endpoint.replace(/\\/$/, '') + '/models').catch(() => null);\nif (!res || !res.ok) throw new Error('LM Studio server unreachable at ' + endpoint);","typeGuard":null,"tryCatchPattern":"try {\n  await client.evaluate(prompt);\n} catch (e) {\n  if (e.message.startsWith('Failed to communicate with LM Studio server:')) {\n    const cause = e.message.replace('Failed to communicate with LM Studio server: ', '');\n    // inspect cause: ECONNREFUSED => server not running; JSON errors => non-JSON response\n  } else {\n    throw e;\n  }\n}","preventionTips":["Start the LM Studio local server before using AI features.","Health-check the endpoint at app startup.","Remember this wrapper masks the original error type — parse the message for the cause."],"tags":["network","wrapper","lm-studio"],"backgroundTag":"api-request-failed","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}