Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit d1a5631

Browse files
committed
#98 Now including host and port in error messages for loading REST modules
1 parent 2134d4b commit d1a5631

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/main/java/com/marklogic/client/ext/modulesloader/impl/DefaultModulesLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ protected void executeTask(Runnable r) {
569569
try {
570570
r.run();
571571
} catch (Exception e) {
572-
failureListeners.forEach(listener -> listener.processFailure(e));
572+
failureListeners.forEach(listener -> listener.processFailure(e, this.client));
573573
}
574574
});
575575
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.marklogic.client.ext.modulesloader.impl;
22

3+
import com.marklogic.client.DatabaseClient;
4+
35
/**
4-
* Ideally this would just have been a Consumer that receives an instance of Throwable. And also, it's only for
5-
* loading REST modules, which DefaultModulesLoader loads by default in parallel.
6+
* This is just for loading REST modules, which DefaultModulesLoader loads by default in parallel. The DatabaseClient
7+
* is provided so that the implementation can e.g. capture information about the host and port in use.
68
*/
79
public interface LoadModulesFailureListener {
810

9-
void processFailure(Throwable throwable);
11+
void processFailure(Throwable throwable, DatabaseClient databaseClient);
1012

1113
}

src/main/java/com/marklogic/client/ext/modulesloader/impl/SimpleLoadModulesFailureListener.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.marklogic.client.ext.modulesloader.impl;
22

3+
import com.marklogic.client.DatabaseClient;
34
import com.marklogic.client.ext.helper.LoggingObject;
45

56
import java.util.function.Supplier;
@@ -9,12 +10,14 @@ public class SimpleLoadModulesFailureListener extends LoggingObject implements L
910
private Throwable firstThrowable;
1011

1112
@Override
12-
public void processFailure(Throwable throwable) {
13+
public void processFailure(Throwable throwable, DatabaseClient databaseClient) {
14+
final String message = format("Error occurred while loading modules; host: %s; port: %d; cause: %s", databaseClient.getHost(), databaseClient.getPort(), throwable.getMessage());
15+
final RuntimeException exception = new RuntimeException(message, throwable);
1316
if (firstThrowable == null) {
14-
firstThrowable = throwable;
17+
firstThrowable = exception;
1518
}
1619
if (logger.isErrorEnabled()) {
17-
logger.error("Error caught while loading modules, cause: " + throwable.getMessage(), throwable);
20+
logger.error(message, throwable);
1821
}
1922
}
2023

0 commit comments

Comments
 (0)