fix: TDZ crash on SSH connect failure — sessionId referenced before assignment
When SSH timed out, the onClose callback referenced `const sessionId` before connect() resolved, causing a Temporal Dead Zone ReferenceError that killed the process. Changed to `let` with try/catch so connection failures send an error message to the client instead of crashing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8d95fc5652
commit
639ac329a8
@ -45,16 +45,22 @@ export class TerminalGateway {
|
||||
private async handleMessage(client: any, msg: any) {
|
||||
switch (msg.type) {
|
||||
case 'connect': {
|
||||
const sessionId = await this.ssh.connect(
|
||||
let sessionId = '';
|
||||
try {
|
||||
sessionId = await this.ssh.connect(
|
||||
msg.hostId,
|
||||
(data) => this.send(client, { type: 'data', sessionId, data }),
|
||||
(reason) => this.send(client, { type: 'disconnected', sessionId, reason }),
|
||||
async (fingerprint, isNew) => {
|
||||
// Send verification request to client
|
||||
this.send(client, { type: 'host-key-verify', fingerprint, isNew });
|
||||
return true; // auto-accept for now, full flow in Task 12
|
||||
},
|
||||
);
|
||||
} catch (err: any) {
|
||||
this.logger.error(`[WS] SSH connect failed: ${err.message}`);
|
||||
this.send(client, { type: 'error', message: `Connection failed: ${err.message}` });
|
||||
break;
|
||||
}
|
||||
const sessions = this.clientSessions.get(client) || [];
|
||||
sessions.push(sessionId);
|
||||
this.clientSessions.set(client, sessions);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user