Skip to content

Commit

Permalink
fix uncaught exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sadzurami committed Feb 22, 2024
1 parent d24569d commit 778f0ec
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions components/connection_protocols/tcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ class TCPConnection extends BaseConnection {
buf.writeUInt32LE(data.length, 0);
buf.write(MAGIC, 4);
data.copy(buf, 8);
this.stream.write(buf);

try {
this.stream.write(buf);
} catch (error) {
this._debug('Error writing to socket: ' + error.message);
}
}

/**
Expand All @@ -187,7 +192,14 @@ class TCPConnection extends BaseConnection {
}
}

let message = this.stream.read(this._messageLength);
let message;

try {
message = this.stream.read(this._messageLength);
} catch (error) {
this._debug('Error reading from socket: ' + error.message);
}

if (!message) {
this._debug('Got incomplete message; expecting ' + this._messageLength + ' more bytes');
return;
Expand Down

0 comments on commit 778f0ec

Please sign in to comment.