Skip to content

Commit 2a56f2f

Browse files
committed
Added link in lonsole to show error details
1 parent f4e426a commit 2a56f2f

File tree

2 files changed

+80
-16
lines changed

2 files changed

+80
-16
lines changed

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818
import org.jetbrains.annotations.Nullable;
1919

2020
import java.awt.*;
21+
import java.util.HashMap;
2122
import java.util.Map;
2223

2324
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.console.event.QueryParametersRetrievalErrorEvent.PARAMS_ERROR_COMMON_MSG;
24-
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.util.ExceptionWrapper.getCause;
25-
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.util.ExceptionWrapper.truncateString;
25+
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.console.log.ShowExceptionDetailsFilter.SHOW_DETAILS;
2626
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.util.ExceptionWrapper.wrapExceptionInMeaningMessage;
2727

2828
public class LogPanel implements Disposable {
29-
3029
private ConsoleView log;
30+
private Map<String, String> exceptions = new HashMap<>();
31+
private Map<String, String> causes = new HashMap<>();
3132

3233
public void initialize(GraphConsoleView graphConsoleView, Project project) {
3334
MessageBus messageBus = project.getMessageBus();
@@ -36,6 +37,7 @@ public void initialize(GraphConsoleView graphConsoleView, Project project) {
3637
.createBuilder(project)
3738
.getConsole();
3839
log.addMessageFilter(new GoToTabFilter(log));
40+
log.addMessageFilter(new ShowExceptionDetailsFilter(log, exceptions));
3941

4042
Disposer.register(graphConsoleView, log);
4143
graphConsoleView.getLogTab().add(log.getComponent(), BorderLayout.CENTER);
@@ -110,8 +112,10 @@ public void metadataRefreshSucceed(DataSourceApi nodeDataSource, DataSourceMetad
110112

111113
@Override
112114
public void metadataRefreshFailed(DataSourceApi nodeDataSource, Exception exception) {
113-
error(String.format("DataSource[%s] - metadata refresh failed. Reason: ", nodeDataSource.getName()));
114-
printException(exception);
115+
String prefix = String.format("DataSource[%s] - metadata refresh failed. Reason: ", nodeDataSource.getName());
116+
error(prefix);
117+
String errorMessage = prefix + printException(exception) + "\n";
118+
exceptions.put(errorMessage, exception.getMessage());
115119
newLine();
116120
}
117121
});
@@ -123,19 +127,19 @@ public void metadataRefreshFailed(DataSourceApi nodeDataSource, Exception except
123127
});
124128
}
125129

126-
public void userInput(String message) {
130+
private void userInput(String message) {
127131
log.print(message, ConsoleViewContentType.USER_INPUT);
128132
}
129133

130-
public void printParametersMap(Map<String, Object> parameters) {
134+
private void printParametersMap(Map<String, Object> parameters) {
131135
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
132136
String message = String.format("%s: %s", entry.getKey(), entry.getValue());
133137
log.print(message, ConsoleViewContentType.USER_INPUT);
134138
newLine();
135139
}
136140
}
137141

138-
public void info(String message) {
142+
private void info(String message) {
139143
log.print(message, ConsoleViewContentType.NORMAL_OUTPUT);
140144
}
141145

@@ -145,20 +149,19 @@ public void error(@Nullable String message) {
145149
}
146150
}
147151

148-
public void printException(Exception exception) {
152+
private String printException(Exception exception) {
153+
String errorMessage;
149154
if (exception.getMessage() != null) {
150-
error(wrapExceptionInMeaningMessage(exception));
155+
errorMessage = wrapExceptionInMeaningMessage(exception) + " " + SHOW_DETAILS;
151156
} else {
152-
error(exception.toString());
157+
errorMessage = exception.toString() + " " + SHOW_DETAILS;
153158
}
159+
error(errorMessage);
154160
newLine();
155-
156-
String cause = getCause(exception);
157-
error(truncateString(cause, 100));
161+
return errorMessage;
158162
}
159163

160-
161-
public void newLine() {
164+
private void newLine() {
162165
log.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
163166
}
164167

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.console.log;
2+
3+
import com.intellij.execution.filters.Filter;
4+
import com.intellij.execution.filters.HyperlinkInfo;
5+
import com.intellij.execution.ui.ConsoleView;
6+
import com.intellij.icons.AllIcons;
7+
import com.intellij.openapi.ui.popup.JBPopupFactory;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
import javax.swing.*;
12+
import java.util.Map;
13+
import java.util.Optional;
14+
15+
public class ShowExceptionDetailsFilter implements Filter {
16+
public static final String SHOW_DETAILS = "Show details";
17+
18+
private ConsoleView log;
19+
private Map<String, String> exceptions;
20+
21+
ShowExceptionDetailsFilter(ConsoleView log, Map<String, String> exceptions) {
22+
this.log = log;
23+
this.exceptions = exceptions;
24+
}
25+
26+
@Nullable
27+
@Override
28+
public Result applyFilter(@NotNull String textLine, int endPoint) {
29+
return createLink(textLine, endPoint, SHOW_DETAILS).orElse(null);
30+
}
31+
32+
private Optional<Filter.Result> createLink(String textLine, int endPoint, String linkText) {
33+
int startPoint = endPoint - textLine.length();
34+
35+
int tabLinkPos = textLine.lastIndexOf(linkText);
36+
if (tabLinkPos > -1) {
37+
HyperlinkInfo showPopup = e -> {
38+
showPopup("Error details", exceptions.get(textLine));
39+
};
40+
Result graphTabLink = new Result(
41+
startPoint + tabLinkPos,
42+
startPoint + tabLinkPos + linkText.length(),
43+
showPopup);
44+
45+
return Optional.of(graphTabLink);
46+
}
47+
return Optional.empty();
48+
}
49+
50+
private void showPopup(String title, String text) {
51+
JBPopupFactory.getInstance()
52+
.createComponentPopupBuilder(
53+
new JLabel(text,
54+
AllIcons.General.Error,
55+
JLabel.LEFT),
56+
log.getComponent())
57+
.setTitle(title)
58+
.createPopup()
59+
.showInFocusCenter();
60+
}
61+
}

0 commit comments

Comments
 (0)