Skip to content

Commit f041b56

Browse files
committed
Remove inner exception for UnableToConnectToHost. Fixes #1035
This improves diagnostics by removing potentially-confusing or distracting information.
1 parent 010d8f5 commit f041b56

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,11 +1008,11 @@ private async Task<bool> OpenTcpSocketAsync(ConnectionSettings cs, ILoadBalancer
10081008
#endif
10091009
}
10101010
}
1011-
catch (ObjectDisposedException ex) when (cancellationToken.IsCancellationRequested)
1011+
catch (ObjectDisposedException) when (cancellationToken.IsCancellationRequested)
10121012
{
10131013
SafeDispose(ref tcpClient);
10141014
Log.Info("Session{0} connect timeout expired connecting to IpAddress {1} for HostName '{2}'", m_logArguments[0], ipAddress, hostName);
1015-
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.", ex);
1015+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.");
10161016
}
10171017
}
10181018
}
@@ -1069,10 +1069,10 @@ private async Task<bool> OpenUnixSocketAsync(ConnectionSettings cs, IOBehavior i
10691069
socket.Connect(unixEp);
10701070
}
10711071
}
1072-
catch (ObjectDisposedException ex) when (cancellationToken.IsCancellationRequested)
1072+
catch (ObjectDisposedException) when (cancellationToken.IsCancellationRequested)
10731073
{
10741074
Log.Info("Session{0} connect timeout expired connecting to UNIX Socket '{1}'", m_logArguments);
1075-
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.", ex);
1075+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.");
10761076
}
10771077
}
10781078
}
@@ -1126,7 +1126,7 @@ private async Task<bool> OpenNamedPipeAsync(ConnectionSettings cs, int startTick
11261126
{
11271127
m_logArguments[1] = cs.PipeName;
11281128
Log.Info("Session{0} connect timeout expired connecting to named pipe '{1}'", m_logArguments);
1129-
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.", ex);
1129+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.");
11301130
}
11311131
}
11321132
}

src/MySqlConnector/MySqlConnection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ internal async Task OpenAsync(IOBehavior? ioBehavior, CancellationToken cancella
422422
cancellationToken.ThrowIfCancellationRequested();
423423
throw;
424424
}
425-
catch (SocketException ex)
425+
catch (SocketException)
426426
{
427427
SetState(ConnectionState.Closed);
428-
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Unable to connect to any of the specified MySQL hosts.", ex);
428+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Unable to connect to any of the specified MySQL hosts.");
429429
}
430430

431431
#if !NETSTANDARD1_3
@@ -885,10 +885,10 @@ private async ValueTask<ServerSession> CreateSessionAsync(ConnectionPool? pool,
885885
return session;
886886
}
887887
}
888-
catch (OperationCanceledException ex) when (timeoutSource?.IsCancellationRequested ?? false)
888+
catch (OperationCanceledException) when (timeoutSource?.IsCancellationRequested ?? false)
889889
{
890890
var messageSuffix = (pool?.IsEmpty ?? false) ? " All pooled connections are in use." : "";
891-
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired." + messageSuffix, ex);
891+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired." + messageSuffix);
892892
}
893893
catch (MySqlException ex) when ((timeoutSource?.IsCancellationRequested ?? false) || (ex.ErrorCode == MySqlErrorCode.CommandTimeoutExpired))
894894
{

0 commit comments

Comments
 (0)