Skip to content

Commit 96b1da6

Browse files
committed
Review changes
1 parent 71b303e commit 96b1da6

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

database/opencypher/src/main/java/com/neueda/jetbrains/plugin/graphdb/database/opencypher/gremlin/OpenCypherGremlinDatabase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ public GraphMetadata metadata() {
148148

149149
return new OpenCypherGremlinGraphMetadata(labelResult, relResult, vertexPropResult, edgePropResult);
150150
} catch (InterruptedException | ExecutionException e) {
151-
throw new RuntimeException(e);
151+
String exceptionMessage = wrapExceptionInMeaningMessage(e);
152+
throw new OpenCypherGremlinException(exceptionMessage, e);
152153
} finally {
153154
gremlinClient.close();
154155
}

database/opencypher/src/main/java/com/neueda/jetbrains/plugin/graphdb/database/opencypher/gremlin/exceptions/ExceptionErrorMessages.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ public enum ExceptionErrorMessages {
55
SYNTAX_WARNING("Please note that Cypher query is translated to Gremlin and may fail " +
66
"because of translation or database specifics. Make sure that flavor is properly configured in database connection configuration."),
77
SERIALIZER_EXCEPTION("Wrong serializer selected. Please check connection configuration."),
8-
RESPONSE_EXCEPTION("Database connection failed. Please check database configuration and retry to connect."),
9-
CONNECTION_EXCEPTION("Database connection failed. Please check database configuration and retry to connect.");
8+
RESPONSE_EXCEPTION("Database connection failed. Please check database configuration (including username and password) and retry to connect."),
9+
CONNECTION_EXCEPTION("Database connection failed. Please check database configuration (including username and password) and retry to connect.");
1010

1111
private final String description;
1212

database/opencypher/src/main/java/com/neueda/jetbrains/plugin/graphdb/database/opencypher/gremlin/exceptions/ExceptionWrapper.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.neueda.jetbrains.plugin.graphdb.database.opencypher.gremlin.exceptions;
22

3-
import org.apache.tinkerpop.gremlin.driver.exception.ConnectionException;
4-
import org.apache.tinkerpop.gremlin.driver.exception.ResponseException;
5-
import org.apache.tinkerpop.gremlin.driver.ser.SerializationException;
6-
73
import java.io.PrintWriter;
84
import java.io.StringWriter;
5+
import java.util.HashSet;
6+
import java.util.Set;
97

108
public class ExceptionWrapper {
119
public static final int SHORT_STRING_LENGTH = 150;
@@ -38,10 +36,13 @@ public static String ellipseString(String text, int targetLength) {
3836

3937
public static String getCause(Exception exception) {
4038
StringBuilder exceptionCauses = new StringBuilder();
41-
Throwable cause = exception.getCause();
42-
while (cause != null) {
43-
exceptionCauses.append(cause.getMessage()).append("\n");
44-
cause = cause.getCause();
39+
Set<Throwable> causesList = new HashSet<>();
40+
Throwable cause;
41+
42+
while (exception.getCause() != null && !causesList.contains(exception.getCause())) {
43+
cause = exception.getCause();
44+
causesList.add(cause);
45+
exceptionCauses.append(cause).append("\n");
4546
}
4647
return exceptionCauses.toString();
4748
}
@@ -55,21 +56,22 @@ public static String getStackTrace(final Throwable throwable) {
5556

5657
public static String wrapExceptionInMeaningMessage(Exception exception) {
5758
String exceptionMessage = exception.getMessage();
58-
if (exceptionMessage.isEmpty()) {
59+
if (exceptionMessage != null) {
60+
if (exceptionMessage.contains("SerializationException")) {
61+
return ExceptionErrorMessages.SERIALIZER_EXCEPTION.getDescription();
62+
}
63+
if (exceptionMessage.contains("ResponseException")) {
64+
return ExceptionErrorMessages.RESPONSE_EXCEPTION.getDescription();
65+
}
66+
if (exceptionMessage.contains("ConnectionException")) {
67+
return ExceptionErrorMessages.CONNECTION_EXCEPTION.getDescription();
68+
}
69+
if (exceptionMessage.length() > SHORT_STRING_LENGTH) {
70+
return ellipseString(exceptionMessage, SHORT_STRING_LENGTH);
71+
}
72+
return exceptionMessage;
73+
} else {
5974
return ExceptionErrorMessages.ERROR_OCCURRED.getDescription();
6075
}
61-
if (exceptionMessage.contains("SerializationException")) {
62-
return ExceptionErrorMessages.SERIALIZER_EXCEPTION.getDescription();
63-
}
64-
if (exceptionMessage.contains("ResponseException")) {
65-
return ExceptionErrorMessages.RESPONSE_EXCEPTION.getDescription();
66-
}
67-
if (exceptionMessage.contains("ConnectionException")) {
68-
return ExceptionErrorMessages.CONNECTION_EXCEPTION.getDescription();
69-
}
70-
if (exceptionMessage.length() > SHORT_STRING_LENGTH) {
71-
return ellipseString(exceptionMessage, SHORT_STRING_LENGTH);
72-
}
73-
return exceptionMessage;
7476
}
7577
}

testing/integration-tinkerpop/src/test/java/com/neueda/jetbrains/plugin/graphdb/test/integration/opencypher/gremlin/OpenCypherGremlinDatabaseTestSecure.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public void wrongCredentials() throws Exception {
4040
OpenCypherGremlinDatabase database = new OpenCypherGremlinDatabase(config);
4141

4242
assertThatThrownBy(() -> database.execute("RETURN 1"))
43-
.hasMessageContaining("Username and/or password are incorrect");
43+
.hasMessageContaining("Database connection failed. Please check database configuration (including username and password) and retry" +
44+
"to connect.");
4445
}
4546

4647
@Test

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/ui/console/log/LogPanel.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import javax.swing.*;
2828
import java.awt.*;
29-
import java.util.HashMap;
3029
import java.util.Map;
3130

3231
import static com.neueda.jetbrains.plugin.graphdb.database.opencypher.gremlin.exceptions.ExceptionWrapper.*;
@@ -119,11 +118,9 @@ public void metadataRefreshSucceed(DataSourceApi nodeDataSource, DataSourceMetad
119118

120119
@Override
121120
public void metadataRefreshFailed(DataSourceApi nodeDataSource, Exception exception) {
122-
Map<String, String> exceptions = new HashMap<>();
123121
String prefix = String.format("DataSource[%s] - metadata refresh failed. Reason: ", nodeDataSource.getName());
124122
error(prefix);
125-
String errorMessage = prefix + printException(exception) + "\n";
126-
exceptions.put(errorMessage, exception.getMessage());
123+
printException(exception);
127124
newLine();
128125
}
129126
});
@@ -160,13 +157,13 @@ public void error(@Nullable String message) {
160157
private String printException(Exception exception) {
161158
String errorMessage;
162159
if (exception.getMessage() != null) {
163-
errorMessage = wrapExceptionInMeaningMessage(exception);
160+
errorMessage = exception.getMessage();
164161
} else {
165162
errorMessage = exception.toString();
166163
}
167164
error(errorMessage);
168165
String newLine = System.lineSeparator();
169-
String details = exception.getMessage() + newLine + getCause(exception) + newLine + getStackTrace(exception);
166+
String details = getCause(exception) + newLine + getStackTrace(exception);
170167
log.printHyperlink(" " + SHOW_DETAILS, p -> showPopup("Error details", details, exception));
171168
newLine();
172169
return errorMessage;

0 commit comments

Comments
 (0)