fix: add detailed error logging for SDK process failures
The "exited with code 1" error was hiding the real cause. Now: - Logs full error object to console (message, stack, cause, stderr) - Extracts stderr/cause from SDK error and includes in user-facing message - Adds "Details:" section to the error when extra info is available This will help diagnose why old sessions fail on some machines while new sessions work fine with the same provider config. - src/lib/claude-client.ts: enhanced catch block with console.error logging and stderr/cause extraction for error messages
This commit is contained in:
1 parent
959b2bde06
commit
7b9de0ab23
1 file changed
+16
-1
@@ -719,6 +719,20 @@ export function streamClaude(options: ClaudeStreamOptions): ReadableStream<strin
|
||||
controller.close();
|
||||
} catch (error) {
|
||||
const rawMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
// Log full error details for debugging (visible in terminal / dev tools)
|
||||
console.error('[claude-client] Stream error:', {
|
||||
message: rawMessage,
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
cause: error instanceof Error ? (error as { cause?: unknown }).cause : undefined,
|
||||
stderr: error instanceof Error ? (error as { stderr?: string }).stderr : undefined,
|
||||
code: error instanceof Error ? (error as NodeJS.ErrnoException).code : undefined,
|
||||
});
|
||||
|
||||
// Try to extract stderr or cause for more useful error messages
|
||||
const stderr = error instanceof Error ? (error as { stderr?: string }).stderr : undefined;
|
||||
const cause = error instanceof Error ? (error as { cause?: unknown }).cause : undefined;
|
||||
const extraDetail = stderr || (cause instanceof Error ? cause.message : cause ? String(cause) : '');
|
||||
|
||||
let errorMessage = rawMessage;
|
||||
|
||||
// Provide more specific error messages based on error type
|
||||
@@ -728,7 +742,8 @@ export function streamClaude(options: ClaudeStreamOptions): ReadableStream<strin
|
||||
errorMessage = `Claude Code CLI not found. Please ensure Claude Code is installed and available in your PATH.\n\nOriginal error: ${rawMessage}`;
|
||||
} else if (rawMessage.includes('exited with code 1') || rawMessage.includes('exit code 1')) {
|
||||
const providerHint = activeProvider?.name ? ` (Provider: ${activeProvider.name})` : '';
|
||||
errorMessage = `Claude Code process exited with an error${providerHint}. This is often caused by:\n• Invalid or missing API Key\n• Incorrect Base URL configuration\n• Network connectivity issues\n\nOriginal error: ${rawMessage}`;
|
||||
const detailHint = extraDetail ? `\n\nDetails: ${extraDetail}` : '';
|
||||
errorMessage = `Claude Code process exited with an error${providerHint}. This is often caused by:\n• Invalid or missing API Key\n• Incorrect Base URL configuration\n• Network connectivity issues${detailHint}\n\nOriginal error: ${rawMessage}`;
|
||||
} else if (rawMessage.includes('exited with code')) {
|
||||
const providerHint = activeProvider?.name ? ` (Provider: ${activeProvider.name})` : '';
|
||||
errorMessage = `Claude Code process crashed unexpectedly${providerHint}.\n\nOriginal error: ${rawMessage}`;
|
||||
|
||||
Reference in new issue
Block a user