Skip to content

Commit 9612327

Browse files
pendula95Ladicek
authored andcommitted
Improve error reporting
1 parent 19f8f6e commit 9612327

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/main/java/io/vertx/redis/client/impl/RedisClusterClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ private void connect(Slots slots, Completable<RedisConnection> promise) {
160160

161161
private void connect(Slots slots, RedisClusterConnectOptions connectOptions, Completable<RedisConnection> onConnected) {
162162
// create a cluster connection
163-
final Set<Throwable> failures = ConcurrentHashMap.newKeySet();
163+
final Map<String, Throwable> failures = new ConcurrentHashMap<>();
164164
final AtomicInteger counter = new AtomicInteger();
165165
final Map<String, PooledRedisConnection> connections = new HashMap<>();
166166

167167
for (String endpoint : slots.endpoints()) {
168168
connectionManager.getConnection(endpoint, RedisReplicas.NEVER != connectOptions.getUseReplicas() ? Request.cmd(Command.READONLY) : null)
169169
.onFailure(err -> {
170170
// failed try with the next endpoint
171-
failures.add(err);
171+
failures.put(endpoint, err);
172172
connectionComplete(counter, slots, connectOptions, connections, failures, onConnected);
173173
})
174174
.onSuccess(cconn -> {
@@ -184,7 +184,7 @@ private void connect(Slots slots, RedisClusterConnectOptions connectOptions, Com
184184
}
185185

186186
private void connectionComplete(AtomicInteger counter, Slots slots, RedisClusterConnectOptions connectOptions,
187-
Map<String, PooledRedisConnection> connections, Set<Throwable> failures, Completable<RedisConnection> onConnected) {
187+
Map<String, PooledRedisConnection> connections, Map<String, Throwable> failures, Completable<RedisConnection> onConnected) {
188188
if (counter.incrementAndGet() == slots.endpoints().length) {
189189
// end condition
190190
if (!failures.isEmpty()) {
@@ -201,8 +201,8 @@ private void connectionComplete(AtomicInteger counter, Slots slots, RedisCluster
201201
}
202202
// return
203203
StringBuilder message = new StringBuilder("Failed to connect to all nodes of the cluster");
204-
for (Throwable failure : failures) {
205-
message.append("\n- ").append(failure);
204+
for (Map.Entry<String, Throwable> failure: failures.entrySet()) {
205+
message.append(String.format("\n- %s: %s", failure.getKey(), failure.getValue().getMessage()));
206206
}
207207
onConnected.fail(new RedisConnectException(message.toString()));
208208
} else {

0 commit comments

Comments
 (0)