Skip to content

Commit a85ddea

Browse files
committed
Review changes
1 parent 71b303e commit a85ddea

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
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: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
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;
95

@@ -38,10 +34,11 @@ public static String ellipseString(String text, int targetLength) {
3834

3935
public static String getCause(Exception exception) {
4036
StringBuilder exceptionCauses = new StringBuilder();
41-
Throwable cause = exception.getCause();
42-
while (cause != null) {
43-
exceptionCauses.append(cause.getMessage()).append("\n");
44-
cause = cause.getCause();
37+
Throwable cause = null;
38+
39+
while (exception.getCause() != null && exception.getCause() != cause) {
40+
cause = exception.getCause();
41+
exceptionCauses.append(cause).append("\n");
4542
}
4643
return exceptionCauses.toString();
4744
}
@@ -55,21 +52,22 @@ public static String getStackTrace(final Throwable throwable) {
5552

5653
public static String wrapExceptionInMeaningMessage(Exception exception) {
5754
String exceptionMessage = exception.getMessage();
58-
if (exceptionMessage.isEmpty()) {
55+
if (exceptionMessage != null) {
56+
if (exceptionMessage.contains("SerializationException")) {
57+
return ExceptionErrorMessages.SERIALIZER_EXCEPTION.getDescription();
58+
}
59+
if (exceptionMessage.contains("ResponseException")) {
60+
return ExceptionErrorMessages.RESPONSE_EXCEPTION.getDescription();
61+
}
62+
if (exceptionMessage.contains("ConnectionException")) {
63+
return ExceptionErrorMessages.CONNECTION_EXCEPTION.getDescription();
64+
}
65+
if (exceptionMessage.length() > SHORT_STRING_LENGTH) {
66+
return ellipseString(exceptionMessage, SHORT_STRING_LENGTH);
67+
}
68+
return exceptionMessage;
69+
} else {
5970
return ExceptionErrorMessages.ERROR_OCCURRED.getDescription();
6071
}
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;
7472
}
7573
}

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: 2 additions & 5 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,7 +157,7 @@ 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
}

0 commit comments

Comments
 (0)