From 6be368c002f1ad81df2c0db66fd03f240eb2a8f1 Mon Sep 17 00:00:00 2001 From: everhardt Date: Wed, 31 Jan 2024 21:28:25 +0100 Subject: [PATCH] fix: catch error thrown in getMultipleHoldingRegisters (#543) --- servers/servertcp_handler.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/servers/servertcp_handler.js b/servers/servertcp_handler.js index fe5034f..aaf7a6e 100644 --- a/servers/servertcp_handler.js +++ b/servers/servertcp_handler.js @@ -296,7 +296,13 @@ function _handleReadMultipleRegisters(requestBuffer, vector, unitID, callback) { } }); } else { - const values = vector.getMultipleHoldingRegisters(address, length, unitID); + let values; + try { + values = vector.getMultipleHoldingRegisters(address, length, unitID); + } catch (error) { + callback(error); + return; + } if (values.length === length) { for (i = 0; i < length; i++) { tryAndHandlePromiseOrValue(i, values); @@ -434,7 +440,13 @@ function _handleReadMultipleRegistersEnron(requestBuffer, vector, unitID, enronT } }); } else { - const values = vector.getMultipleHoldingRegisters(address, length, unitID); + let values; + try { + values = vector.getMultipleHoldingRegisters(address, length, unitID); + } catch (error) { + callback(error); + return; + } if (values.length === length) { for (i = 0; i < length; i++) { tryAndHandlePromiseOrValue(i, values);