debug: add stderr to error response

This commit is contained in:
aedes
2026-04-20 16:58:38 +03:00
parent ff6214d76b
commit 10e8d8df1a

View File

@@ -49,13 +49,23 @@ app.post('/api/chat', (req, res) => {
res.write(`data: ${JSON.stringify({ text: chunk.toString() })}\n\n`); res.write(`data: ${JSON.stringify({ text: chunk.toString() })}\n\n`);
}); });
let stderrBuf = '';
proc.stderr.on('data', (chunk) => { proc.stderr.on('data', (chunk) => {
console.error('[claude stderr]', chunk.toString().substring(0, 300)); const s = chunk.toString();
stderrBuf += s;
console.error('[claude stderr]', s.substring(0, 500));
}); });
proc.on('close', (code) => { proc.on('error', (err) => {
console.error('[spawn error]', err.message);
res.write(`data: ${JSON.stringify({ error: `spawn: ${err.message}` })}\n\n`);
});
proc.on('close', (code, signal) => {
console.log(`[claude close] code=${code} signal=${signal} stderr=${stderrBuf.substring(0,300)}`);
if (code !== 0) { if (code !== 0) {
res.write(`data: ${JSON.stringify({ error: `Ошибка (code ${code}). Проверь auth: claude --version` })}\n\n`); const msg = stderrBuf.trim() || `code=${code} signal=${signal}`;
res.write(`data: ${JSON.stringify({ error: msg.substring(0, 500) })}\n\n`);
} }
res.write('data: [DONE]\n\n'); res.write('data: [DONE]\n\n');
res.end(); res.end();