From b45bba6529431f7147f1e2cfad7b019f1005e24c Mon Sep 17 00:00:00 2001 From: "victor.irizar" Date: Fri, 21 Jun 2024 03:33:00 +0200 Subject: [PATCH 1/3] Added exception unwinding and logging on MqttRelay module when connection error throws --- .../MTConnect.NET-AgentModule-MqttRelay/Module.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs b/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs index 62524cb5..a5773eaf 100644 --- a/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs +++ b/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs @@ -216,7 +216,20 @@ private async Task Worker() } catch (Exception ex) { + Log(MTConnectLogLevel.Warning, $"MQTT Relay Connection Error : {ex.Message}"); + + var current = current.InnerException; + + while( current != null ) + { + Log(MTConnectLogLevel.Warning, $"MQTT Relay Connection Error (InnerException) : {current.Message}"); + current = current.InnerException; + } + + Log(MTConnectLogLevel.Warning, $"MQTT Relay Connection Error (BaseException) : {ex.GetBaseException().ToString()}"); + + } finally { From 5c45a7b076eebf7c83c83f96497ee1302b4e7dcb Mon Sep 17 00:00:00 2001 From: Patrick Ritchie Date: Tue, 25 Jun 2024 23:28:20 -0400 Subject: [PATCH 2/3] Fixed issue with variable name --- agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs b/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs index a5773eaf..c12b26c7 100644 --- a/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs +++ b/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs @@ -219,7 +219,7 @@ private async Task Worker() Log(MTConnectLogLevel.Warning, $"MQTT Relay Connection Error : {ex.Message}"); - var current = current.InnerException; + var current = ex.InnerException; while( current != null ) { From e2a518db271a1eb826ea2fe6e4f0c0a240b68a39 Mon Sep 17 00:00:00 2001 From: Patrick Ritchie Date: Tue, 25 Jun 2024 23:29:02 -0400 Subject: [PATCH 3/3] Renamed Exception variables to better distinguish between them --- .../Module.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs b/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs index c12b26c7..2b785dd0 100644 --- a/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs +++ b/agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs @@ -214,22 +214,19 @@ private async Task Worker() await Task.Delay(100); } } - catch (Exception ex) + catch (Exception exception) { - - Log(MTConnectLogLevel.Warning, $"MQTT Relay Connection Error : {ex.Message}"); + Log(MTConnectLogLevel.Warning, $"MQTT Relay Connection Error : {exception.Message}"); - var current = ex.InnerException; + var innerException = exception.InnerException; - while( current != null ) + while (innerException != null) { - Log(MTConnectLogLevel.Warning, $"MQTT Relay Connection Error (InnerException) : {current.Message}"); - current = current.InnerException; + Log(MTConnectLogLevel.Warning, $"MQTT Relay Connection Error (InnerException) : {innerException.Message}"); + innerException = innerException.InnerException; } - Log(MTConnectLogLevel.Warning, $"MQTT Relay Connection Error (BaseException) : {ex.GetBaseException().ToString()}"); - - + Log(MTConnectLogLevel.Warning, $"MQTT Relay Connection Error (BaseException) : {exception.GetBaseException().ToString()}"); } finally {