fix: modify how exceptions are printed to reduce noise

When an exception occurs during the connect method,
only the exception message will be printed at the Error log level.
The entire stack trace will be printed when at the Verbose level.

fixes #1273
This commit is contained in:
Andrew Welker
2025-07-25 09:13:42 -05:00
parent 43989b9588
commit 31143f56df

View File

@@ -223,10 +223,7 @@ namespace PepperDash.Core
this.LogDebug("Attempting connect"); this.LogDebug("Attempting connect");
// Cancel reconnect if running. // Cancel reconnect if running.
if (ReconnectTimer != null) ReconnectTimer?.Stop();
{
ReconnectTimer.Stop();
}
// Cleanup the old client if it already exists // Cleanup the old client if it already exists
if (Client != null) if (Client != null)
@@ -268,20 +265,26 @@ namespace PepperDash.Core
if (ie is SocketException) if (ie is SocketException)
{ {
this.LogException(ie, "CONNECTION failure: Cannot reach host"); this.LogError("CONNECTION failure: Cannot reach host");
this.LogVerbose(ie, "Exception details: ");
} }
if (ie is System.Net.Sockets.SocketException socketException) if (ie is System.Net.Sockets.SocketException socketException)
{ {
this.LogException(ie, "Connection failure: Cannot reach {host} on {port}", this.LogError("Connection failure: Cannot reach {host} on {port}",
Hostname, Port); Hostname, Port);
this.LogVerbose(socketException, "SocketException details: ");
} }
if (ie is SshAuthenticationException) if (ie is SshAuthenticationException)
{ {
this.LogException(ie, "Authentication failure for username {userName}", Username); this.LogError("Authentication failure for username {userName}", Username);
this.LogVerbose(ie, "AuthenticationException details: ");
} }
else else
this.LogException(ie, "Error on connect"); {
this.LogError("Error on connect: {error}", ie.Message);
this.LogVerbose(ie, "Exception details: ");
}
DisconnectLogged = true; DisconnectLogged = true;
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED); KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
@@ -306,7 +309,8 @@ namespace PepperDash.Core
catch (Exception e) catch (Exception e)
{ {
var errorLogLevel = DisconnectLogged == true ? Debug.ErrorLogLevel.None : Debug.ErrorLogLevel.Error; var errorLogLevel = DisconnectLogged == true ? Debug.ErrorLogLevel.None : Debug.ErrorLogLevel.Error;
this.LogException(e, "Unhandled exception on connect"); this.LogError("Unhandled exception on connect: {error}", e.Message);
this.LogVerbose(e, "Exception details: ");
DisconnectLogged = true; DisconnectLogged = true;
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED); KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
if (AutoReconnect) if (AutoReconnect)
@@ -465,8 +469,7 @@ namespace PepperDash.Core
/// </summary> /// </summary>
void OnConnectionChange() void OnConnectionChange()
{ {
if (ConnectionChange != null) ConnectionChange?.Invoke(this, new GenericSocketStatusChageEventArgs(this));
ConnectionChange(this, new GenericSocketStatusChageEventArgs(this));
} }
#region IBasicCommunication Members #region IBasicCommunication Members
@@ -474,10 +477,7 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// Sends text to the server /// Sends text to the server
/// </summary> /// </summary>
/// <param name="text"></param> /// <param name="text">The text to send</param>
/// <summary>
/// SendText method
/// </summary>
public void SendText(string text) public void SendText(string text)
{ {
try try
@@ -514,10 +514,7 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// Sends Bytes to the server /// Sends Bytes to the server
/// </summary> /// </summary>
/// <param name="bytes"></param> /// <param name="bytes">The bytes to send</param>
/// <summary>
/// SendBytes method
/// </summary>
public void SendBytes(byte[] bytes) public void SendBytes(byte[] bytes)
{ {
try try