From f0342def330c71ae45aebe6164efbd5c51bbd56e Mon Sep 17 00:00:00 2001 From: Petr Severa Date: Tue, 18 Nov 2025 13:07:25 +0100 Subject: [PATCH 1/3] emit error on serialPort error --- src/connection/nodejs_serial_connection.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/connection/nodejs_serial_connection.js b/src/connection/nodejs_serial_connection.js index 4bc519d..6ee4caa 100644 --- a/src/connection/nodejs_serial_connection.js +++ b/src/connection/nodejs_serial_connection.js @@ -31,7 +31,8 @@ class NodeJSSerialConnection extends SerialConnection { }); this.serialPort.on("error", function(err) { - console.log("SerialPort Error: ", err.message) + console.error("SerialPort Error: ", err.message); + this.emit("error", err); }); this.serialPort.on("data", async (data) => { From 82703bc9f30047ca0248ce3b0384f7420fb8e2d7 Mon Sep 17 00:00:00 2001 From: Petr Severa Date: Tue, 18 Nov 2025 13:09:41 +0100 Subject: [PATCH 2/3] emit error on socket error --- src/connection/tcp_connection.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/connection/tcp_connection.js b/src/connection/tcp_connection.js index eab0e16..6747846 100644 --- a/src/connection/tcp_connection.js +++ b/src/connection/tcp_connection.js @@ -28,6 +28,7 @@ class TCPConnection extends Connection { // handle errors this.socket.on('error', (error) => { console.error('Connection Error', error); + this.emit("error", error); }); // handle socket close From 77d523e1de5128d723483b932b9dbb98c194a7ed Mon Sep 17 00:00:00 2001 From: Petr Severa Date: Tue, 18 Nov 2025 13:27:18 +0100 Subject: [PATCH 3/3] Refactor error handling to use arrow function --- src/connection/nodejs_serial_connection.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/connection/nodejs_serial_connection.js b/src/connection/nodejs_serial_connection.js index 6ee4caa..3f3d617 100644 --- a/src/connection/nodejs_serial_connection.js +++ b/src/connection/nodejs_serial_connection.js @@ -30,9 +30,9 @@ class NodeJSSerialConnection extends SerialConnection { this.onDisconnected(); }); - this.serialPort.on("error", function(err) { - console.error("SerialPort Error: ", err.message); - this.emit("error", err); + this.serialPort.on("error", (error) => { + console.error("SerialPort Error: ", error.message); + this.emit("error", error); }); this.serialPort.on("data", async (data) => {