From 05717ec830ec163fcf14c5a35cc24f1d71c7b60f Mon Sep 17 00:00:00 2001 From: Frank Wagner Date: Fri, 16 Jun 2023 16:12:00 +0200 Subject: [PATCH] Do not throw InvalidOperationException (#234) --- src/YaNco.Core/Connection.cs | 6 +++++- src/YaNco.Core/RfcServer.cs | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/YaNco.Core/Connection.cs b/src/YaNco.Core/Connection.cs index 21c1da67..33cb8e40 100644 --- a/src/YaNco.Core/Connection.cs +++ b/src/YaNco.Core/Connection.cs @@ -82,9 +82,13 @@ public Connection( catch (Exception ex) { rfcRuntime.Logger.IfSome(l => l.LogException(ex)); + return (null, Prelude.Left(RfcErrorInfo.Error(ex.Message))); } - throw new InvalidOperationException(); + rfcRuntime.Logger.IfSome(l => l.LogError( + $"Invalid rfc connection message {msg.GetType()}")); + return (null, Prelude.Left(RfcErrorInfo.Error($"Invalid rfc connection message {msg.GetType().Name}"))); + }); } diff --git a/src/YaNco.Core/RfcServer.cs b/src/YaNco.Core/RfcServer.cs index 011b035c..e12bf2a9 100644 --- a/src/YaNco.Core/RfcServer.cs +++ b/src/YaNco.Core/RfcServer.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading; using Dbosoft.Functional; using LanguageExt; @@ -75,9 +74,13 @@ private RfcServer(IRfcServerHandle serverHandle, IRfcRuntime rfcRuntime) catch (Exception ex) { rfcRuntime.Logger.IfSome(l => l.LogException(ex)); + return (null, Prelude.Left(RfcErrorInfo.Error(ex.Message))); } - throw new InvalidOperationException(); + rfcRuntime.Logger.IfSome(l => l.LogError( + $"Invalid rfc server message {msg.GetType()}")); + return (null, Prelude.Left(RfcErrorInfo.Error($"Invalid rfc server message {msg.GetType().Name}"))); + }); }