Skip to content

Commit 3777907

Browse files
committed
Handle spurious errors on Windows.
1 parent 71223e4 commit 3777907

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/tcp_cat.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,14 @@ export class TcpCatReadLine extends EventEmitter {
373373
this.tcpClient.setEncoding(this.encoding);
374374
}
375375
this.tcpClient.on('data', this.onDataCb.bind(this));
376-
this.tcpClient.once('close', this.onCloseCb.bind(this));
377-
this.tcpClient.once('error', (e) => {
378-
if ((e as any).code === 'ECONNREFUSED') {
379-
// We expect this when there is no server running. Do nothing
380-
} else {
381-
console.log(e);
382-
process.exit(0);
383-
}
376+
this.tcpClient.on('close', this.onCloseCb.bind(this));
377+
this.tcpClient.on('error', (e) => {
378+
// It is normal to get 'ECONNREFUSED' but on Windows you may also get
379+
// ECONNRESET. We expect 'ECONNREFUSED' if the server has not yet started.
380+
// Just ignore the errors as the connection fails or closes anyways
381+
382+
// const code = (e as any).code;
383+
// console.log(`Error code = ${code}`);
384384
});
385385
this.tcpClient.connect(this.port, this.host, cb);
386386
}
@@ -605,4 +605,9 @@ try {
605605
}
606606
catch (e) {
607607
console.error(e);
608+
console.error(e.stack);
609+
console.error('tcpCat crashed... Use Ctrl-C to exit');
610+
setInterval(() => {
611+
console.error('tcpCat crashed... Use Ctrl-C to exit');
612+
}, 1000);
608613
}

0 commit comments

Comments
 (0)