Skip to content

Commit c698ba4

Browse files
Merge pull request #377 from CornedBee/master
Collect all exceptions when selecting an endpoint
2 parents 2746891 + c13c644 commit c698ba4

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

projects/client/RabbitMQ.Client/src/client/api/IEndpointResolverExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static class EndpointResolverExtensions
4949
public static T SelectOne<T>(this IEndpointResolver resolver, Func<AmqpTcpEndpoint, T> selector)
5050
{
5151
var t = default(T);
52-
Exception exception = null;
52+
var exceptions = new List<Exception>();
5353
foreach(var ep in resolver.All())
5454
{
5555
try
@@ -62,13 +62,13 @@ public static T SelectOne<T>(this IEndpointResolver resolver, Func<AmqpTcpEndpoi
6262
}
6363
catch (Exception e)
6464
{
65-
exception = e;
65+
exceptions.Add(e);
6666
}
6767
}
6868

69-
if(Object.Equals(t, default(T)) && exception != null)
69+
if(Object.Equals(t, default(T)) && exceptions.Count > 0)
7070
{
71-
throw exception;
71+
throw new AggregateException(exceptions);
7272
}
7373

7474
return t;

projects/client/RabbitMQ.Client/src/client/exceptions/BrokerUnreachableException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ namespace RabbitMQ.Client.Exceptions
4747
///ConnectionFactory.CreateConnection attempt.</summary>
4848
public class BrokerUnreachableException : IOException
4949
{
50-
///<summary>Construct a BrokerUnreachableException. The inner exception is associated
51-
///with only one connection attempt.</summary>
50+
///<summary>Construct a BrokerUnreachableException. The inner exception is
51+
///an AggregateException holding the errors from multiple connection attempts.</summary>
5252
public BrokerUnreachableException(Exception Inner)
5353
: base("None of the specified endpoints were reachable", Inner)
5454
{

projects/client/RabbitMQ.Client/src/client/impl/Connection.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,6 @@ public class Connection : IConnection
117117
.InformationalVersion;
118118
#endif
119119

120-
#if CORECLR
121-
private static string version = typeof(Connection).GetTypeInfo().Assembly
122-
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
123-
.InformationalVersion;
124-
#else
125-
private static string version = typeof(Connection).Assembly
126-
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
127-
.InformationalVersion;
128-
#endif
129-
130-
131120
// true if we haven't finished connection negotiation.
132121
// In this state socket exceptions are treated as fatal connection
133122
// errors, otherwise as read timeouts

projects/client/Unit/src/unit/TestIEndpointResolverExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public void SelectOneShouldReturnDefaultWhenThereAreNoEndpoints()
7979
public void SelectOneShouldRaiseThrownExceptionWhenThereAreOnlyInaccessibleEndpoints()
8080
{
8181
var ep = new TestEndpointResolver(new List<AmqpTcpEndpoint> { new AmqpTcpEndpoint()});
82-
Assert.Throws<TestEndpointException>(() => ep.SelectOne<AmqpTcpEndpoint>((x) => { throw new TestEndpointException("bananas"); }));
82+
var thrown = Assert.Throws<AggregateException>(() => ep.SelectOne<AmqpTcpEndpoint>((x) => { throw new TestEndpointException("bananas"); }));
83+
Assert.That(thrown.InnerExceptions, Has.Exactly(1).TypeOf<TestEndpointException>());
8384
}
8485

8586
[Test]

0 commit comments

Comments
 (0)