Waiting for terminal activity...
diff --git a/public/claude-ide/terminal.js b/public/claude-ide/terminal.js
index f7cd86b9..2646a7e4 100644
--- a/public/claude-ide/terminal.js
+++ b/public/claude-ide/terminal.js
@@ -893,18 +893,24 @@ class TerminalManager {
const ws = new WebSocket(wsUrl);
ws.onopen = () => {
- this.debugLog('WS', `WebSocket OPENED for terminal ${terminalId}`);
+ this.debugLog('WS', `✅ WebSocket OPENED for terminal ${terminalId}`);
+ this.debugLog('WS', `Checking if terminal exists in map...`);
// Store WebSocket in terminal entry
// NOTE: This assumes initializeXTerm() has already been called
// and this.terminals has the entry
const terminal = this.terminals.get(terminalId);
if (terminal) {
+ this.debugLog('WS', `✅ Terminal found in map, storing WebSocket`);
terminal.ws = ws;
terminal.ready = false; // Will be set to true when 'ready' message received
- this.debugLog('WS', `WebSocket stored in terminal map, waiting for 'ready' message`);
+ this.debugLog('WS', `✅ WebSocket stored in terminal map, waiting for 'ready' message`);
} else {
- this.debugLog('ERROR', `CRITICAL: Terminal ${terminalId} not found in map!`, { terminalsInMap: Array.from(this.terminals.keys()) });
+ this.debugLog('ERROR', `❌ CRITICAL: Terminal ${terminalId} not found in map!`);
+ this.debugLog('ERROR', `Available terminals:`, {
+ count: this.terminals.size,
+ ids: Array.from(this.terminals.keys())
+ });
reject(new Error(`Terminal ${terminalId} not initialized`));
ws.close();
return;
@@ -932,12 +938,52 @@ class TerminalManager {
};
ws.onerror = (error) => {
- this.debugLog('ERROR', `WebSocket error for terminal ${terminalId}`, error);
+ this.debugLog('ERROR', `✖✖✖ WebSocket ERROR for terminal ${terminalId} ✖✖✖`, {
+ type: error.type || 'unknown',
+ message: error.message || 'No error message',
+ error: error
+ });
+ this.debugLog('ERROR', `Check browser console (F12) for full error details`);
reject(error);
};
ws.onclose = (event) => {
- this.debugLog('WS', `WebSocket CLOSED for terminal ${terminalId}`, { code: event.code, reason: event.reason, wasClean: event.wasClean });
+ const closeReasons = {
+ 1000: 'Normal Closure',
+ 1001: 'Endpoint Going Away',
+ 1002: 'Protocol Error',
+ 1003: 'Unsupported Data',
+ 1004: '(Reserved)',
+ 1005: 'No Status Received',
+ 1006: 'Abnormal Closure (connection dropped)',
+ 1007: 'Invalid frame payload data',
+ 1008: 'Policy Violation',
+ 1009: 'Message Too Big',
+ 1010: 'Mandatory Extension',
+ 1011: 'Internal Server Error',
+ 1015: 'TLS Handshake'
+ };
+
+ const closeReason = closeReasons[event.code] || `Unknown (${event.code})`;
+
+ this.debugLog('ERROR', `🔌 WebSocket CLOSED for terminal ${terminalId}`, {
+ code: event.code,
+ reasonName: closeReason,
+ reason: event.reason || 'None provided',
+ wasClean: event.wasClean,
+ timestamp: new Date().toISOString()
+ });
+
+ if (event.code === 1006) {
+ this.debugLog('ERROR', `💡 Code 1006 means connection was dropped abnormally - check server logs`);
+ this.debugLog('ERROR', `💡 Common causes: server crash, network issue, or timeout`);
+ }
+
+ // Show terminals currently in map for debugging
+ this.debugLog('ERROR', `Current terminals in map:`, {
+ count: this.terminals.size,
+ ids: Array.from(this.terminals.keys())
+ });
};
} catch (error) {
this.debugLog('ERROR', `Exception connecting WebSocket`, error);
diff --git a/services/terminal-service.js b/services/terminal-service.js
index 3b68bbc4..5499b375 100644
--- a/services/terminal-service.js
+++ b/services/terminal-service.js
@@ -172,7 +172,11 @@ class TerminalService {
// Handle WebSocket ping (respond with pong)
ws.on('ping', () => {
console.log(`[TerminalService] Ping received from ${terminalId}`);
- ws.pong();
+ try {
+ ws.pong();
+ } catch (error) {
+ console.error(`[TerminalService] Error sending pong:`, error);
+ }
});
// Handle WebSocket pong (response to our ping)
@@ -183,14 +187,18 @@ class TerminalService {
// Handle PTY output - send to client
terminal.pty.onData((data) => {
- console.log(`[TerminalService] PTY data from ${terminalId}: ${data.replace(/\n/g, '\\n').replace(/\r/g, '\\r')}`);
- if (ws.readyState === ws.OPEN) {
- ws.send(JSON.stringify({
- type: 'data',
- data: data
- }));
- } else {
- console.log(`[TerminalService] Cannot send PTY data - WebSocket not open (state: ${ws.readyState})`);
+ try {
+ console.log(`[TerminalService] PTY data from ${terminalId}: ${data.replace(/\n/g, '\\n').replace(/\r/g, '\\r')}`);
+ if (ws.readyState === ws.OPEN) {
+ ws.send(JSON.stringify({
+ type: 'data',
+ data: data
+ }));
+ } else {
+ console.log(`[TerminalService] Cannot send PTY data - WebSocket not open (state: ${ws.readyState})`);
+ }
+ } catch (error) {
+ console.error(`[TerminalService] ERROR sending PTY data to client:`, error);
}
});
@@ -199,13 +207,17 @@ class TerminalService {
console.log(`[TerminalService] PTY EXIT for ${terminalId}: exitCode=${exitCode}, signal=${signal}`);
this.logCommand(terminalId, null, `Terminal exited: ${exitCode || signal}`);
- if (ws.readyState === ws.OPEN) {
- ws.send(JSON.stringify({
- type: 'exit',
- exitCode,
- signal
- }));
- ws.close();
+ try {
+ if (ws.readyState === ws.OPEN) {
+ ws.send(JSON.stringify({
+ type: 'exit',
+ exitCode,
+ signal
+ }));
+ ws.close();
+ }
+ } catch (error) {
+ console.error(`[TerminalService] Error sending exit message:`, error);
}
this.terminals.delete(terminalId);
@@ -221,7 +233,12 @@ class TerminalService {
// Handle WebSocket error
ws.on('error', (error) => {
- console.error(`[TerminalService] WebSocket error for terminal ${terminalId}:`, error);
+ console.error(`[TerminalService] ✖✖✖ WebSocket ERROR for terminal ${terminalId} ✖✖✖`);
+ console.error(`[TerminalService] Error:`, error);
+ console.error(`[TerminalService] Message: ${error.message}`);
+ if (error.stack) {
+ console.error(`[TerminalService] Stack: ${error.stack}`);
+ }
});
// Send initial welcome message
@@ -239,9 +256,13 @@ class TerminalService {
// Send a ping immediately after ready to ensure connection stays alive
setTimeout(() => {
- if (ws.readyState === ws.OPEN) {
- ws.ping();
- console.log(`[TerminalService] Sent ping after ready message`);
+ try {
+ if (ws.readyState === ws.OPEN) {
+ ws.ping();
+ console.log(`[TerminalService] Sent ping after ready message`);
+ }
+ } catch (error) {
+ console.error(`[TerminalService] Error sending ping after ready:`, error);
}
}, 100);
} catch (error) {