{"record":{"id":"b3ee725f147c5c92","repo":"SillyTavern/SillyTavern","slug":"comfyui-returned-an-error-b3ee72","errorCode":null,"errorMessage":"ComfyUI returned an error.","messagePattern":"ComfyUI returned an error\\.","errorType":"exception","errorClass":"Error","httpStatus":500,"severity":"error","filePath":"src/endpoints/stable-diffusion.js","lineNumber":583,"sourceCode":"        const url = new URL(urlJoin(request.body.url, '/prompt'));\n\n        const controller = new AbortController();\n        request.socket.removeAllListeners('close');\n        request.socket.on('close', function () {\n            if (!response.writableEnded && !item) {\n                const interruptUrl = new URL(urlJoin(request.body.url, '/interrupt'));\n                fetch(interruptUrl, { method: 'POST', headers: { 'Authorization': getBasicAuthHeader(request.body.auth) } });\n            }\n            controller.abort();\n        });\n\n        const promptResult = await fetch(url, {\n            method: 'POST',\n            body: request.body.prompt,\n        });\n        if (!promptResult.ok) {\n            const text = await promptResult.text();\n            throw new Error('ComfyUI returned an error.', { cause: tryParse(text) });\n        }\n\n        /** @type {any} */\n        const data = await promptResult.json();\n        const id = data.prompt_id;\n        const historyUrl = new URL(urlJoin(request.body.url, '/history'));\n        while (true) {\n            const result = await fetch(historyUrl);\n            if (!result.ok) {\n                throw new Error('ComfyUI returned an error.');\n            }\n            /** @type {any} */\n            const history = await result.json();\n            item = history[id];\n            if (item) {\n                break;\n            }\n            await delay(100);","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/SillyTavern/SillyTavern/blob/8172dcd0ee672d3cd9a5e5f7af134f91a45cd2b8/src/endpoints/stable-diffusion.js#L565-L601","documentation":"Thrown (then surfaced as HTTP 500 with error.message) inside the ComfyUI /generate route when the POST to the ComfyUI /prompt endpoint returns a non-OK status. The original response body is attached as error.cause via tryParse(text), so the underlying ComfyUI error JSON travels with the Error but only the fixed string reaches the HTTP body.","triggerScenarios":"ComfyUI rejects the submitted prompt workflow JSON (invalid node, missing model, bad wiring) and returns 4xx/5xx on /prompt; the ComfyUI server URL is wrong so the proxy returns an error status; auth required by a reverse proxy and missing/invalid.","commonSituations":"Workflow exported from a newer ComfyUI than the server runs; referenced checkpoint/LoRA not installed on the server; URL field points to a ComfyUI behind basic auth without credentials; server out of VRAM and returning 500.","solutions":["Inspect error.cause (server log: console.error('ComfyUI error:', error)) for the exact ComfyUI response body.","Validate the workflow JSON against the server's installed custom nodes and models before submitting.","Confirm the ComfyUI base URL is reachable and, if behind basic auth, that auth is set correctly.","Retry after freeing VRAM or reducing batch size if the cause indicates an OOM."],"exampleFix":"// before\nif (!promptResult.ok) {\n  const text = await promptResult.text();\n  throw new Error('ComfyUI returned an error.', { cause: tryParse(text) });\n}\n// after - surface status + body so the client can act\nif (!promptResult.ok) {\n  const text = await promptResult.text();\n  throw new Error(`ComfyUI returned HTTP ${promptResult.status}.`, { cause: tryParse(text) ?? text });\n}","handlingStrategy":"try-catch","validationCode":"if (!isValidUrl(url)) throw new Error('Invalid ComfyUI URL');\nif (typeof prompt !== 'object' || prompt === null) throw new Error('Prompt must be a workflow object');","typeGuard":"/** @param {unknown} p */\nconst isComfyPrompt = (p) => typeof p === 'string' || (typeof p === 'object' && p !== null);","tryCatchPattern":"try { const r = await comfyGenerate(url, prompt); }\ncatch (e) {\n  const cause = e.cause;\n  if (cause && cause.node_errors) handleWorkflowErrors(cause);\n  else if (cause && cause.error) handleUpstreamError(cause);\n  else handleNetwork(e);\n}","preventionTips":["Validate the ComfyUI base URL is reachable before submitting.","Keep workflow JSON aligned with the server's installed nodes/models; attach error.cause in logs."],"tags":["comfyui","http-500","network","upstream","workflow"],"backgroundTag":null,"analyzedSha":"8172dcd0ee672d3cd9a5e5f7af134f91a45cd2b8","analyzedAt":"2026-08-13T07:48:40.832Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}