Skip to content

Commit

Permalink
Errors are rendered with '. All IO errors are rendered into tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Mar 15, 2024
1 parent 81aec2f commit 3f9e3e6
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 69 deletions.
2 changes: 2 additions & 0 deletions notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Any IO errors are added as Error tab (pop-up error message is used for internal bugs)
* KX errors from servers are now display with ' (not as symbol)
* Parent folder can be specified in the server form (in add and edit server)
* Persist location of the server list frame for every Studio window

Expand Down
4 changes: 2 additions & 2 deletions src/kx/IPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public static KMessage deserialise(byte[] data, boolean compressed, boolean isLi
}
}

public KMessage deserialise(){
public KMessage deserialise() {
try {
if (b[0] == -128) {
j = 1;
return new KMessage(new K4Exception(rs().toString()));
return new KMessage(new K4Exception("'" + rs().s));
}
return new KMessage(r());
} catch (UnsupportedEncodingException e) {
Expand Down
49 changes: 0 additions & 49 deletions src/studio/kdb/QErrors.java

This file was deleted.

18 changes: 5 additions & 13 deletions src/studio/ui/StudioWindow.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package studio.ui;

import kx.K4Exception;
import kx.KMessage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -1690,7 +1689,6 @@ public static void queryExecutionComplete(EditorTab editor, QueryResult queryRes
editor.getPane().stopClock();
JTextComponent textArea = editor.getTextArea();
textArea.setCursor(textCursor);
Throwable error = queryResult.getError();
if (queryResult.isComplete()) {
long execTime = queryResult.getExecutionTimeInMS();
editor.getPane().setEditorStatus("Last execution time: " + (execTime > 0 ? "" + execTime : "<1") + " ms");
Expand All @@ -1699,19 +1697,13 @@ public static void queryExecutionComplete(EditorTab editor, QueryResult queryRes
}

StudioWindow window = editor.getStudioWindow();
if (error == null || error instanceof K4Exception) {
try {
if (queryResult.isComplete()) {
window.addResultTab(queryResult, "Executed at server: " + queryResult.getServer().getDescription(true) );
}
error = null;
} catch (Throwable exc) {
error = new RuntimeException("Error during result rendering", exc);
log.error("Error during result rendering", exc);
try {
if (queryResult.isComplete()) {
window.addResultTab(queryResult, "Executed at server: " + queryResult.getServer().getDescription(true) );
}
}
} catch (Throwable error) {
log.error("Error during result rendering", error);

if (error != null) {
String message = error.getMessage();
if ((message == null) || (message.length() == 0))
message = "No message with exception. Exception is " + error;
Expand Down
15 changes: 12 additions & 3 deletions src/studio/ui/TabPanel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package studio.ui;

import kx.K4Exception;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import studio.kdb.ListModel;
Expand Down Expand Up @@ -118,9 +119,17 @@ private void initComponents() {
updateFormatting();
} else {
textArea = new JTextPane();
String hint = QErrors.lookup(queryResult.getError().getMessage());
hint = hint == null ? "" : "\nStudio Hint: Possibly this error refers to " + hint;
textArea.setText("An error occurred during execution of the query.\nThe server sent the response:\n" + queryResult.getError().getMessage() + hint);
Throwable error = queryResult.getError();
String msg;
if (error instanceof K4Exception) {
msg = "An error occurred during execution of the query.\nThe server sent the response:\n" + error.getMessage();
} else {
msg = "An unexpected error occurred whilst communicating with server.\nError: " + error.toString();
if (error.getMessage() != null) {
msg += "\nMessage: " + error.getMessage();
}
}
textArea.setText(msg);
textArea.setForeground(Color.RED);
textArea.setEditable(false);
component = new JScrollPane(textArea);
Expand Down
22 changes: 22 additions & 0 deletions test-integration/studio/ui/ResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import studio.kdb.MockQSession;

import java.awt.*;
import java.io.EOFException;
import java.io.IOException;
import java.util.Arrays;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -112,5 +114,25 @@ public void testAuthenticationException() {
textArea.requireText(Pattern.compile(".*error.*Authentication failed.*", Pattern.DOTALL));
}

@Test
public void testEOFException() {
setExpectedNumberOfLogErrors(1);
MockQSession.setResponse(new EOFException());
execute();

JTextComponentFixture textArea = frameFixture.panel("resultPanel0").textBox();
textArea.requireText(Pattern.compile(".*Error: java.io.EOFException", Pattern.DOTALL));
}

@Test
public void testIOException() {
setExpectedNumberOfLogErrors(1);
MockQSession.setResponse(new IOException("ioMessageHere"));
execute();

JTextComponentFixture textArea = frameFixture.panel("resultPanel0").textBox();
textArea.requireText(Pattern.compile(".*Error: java.io.IOException.*ioMessageHere.*", Pattern.DOTALL));
}


}
11 changes: 9 additions & 2 deletions test-integration/studio/ui/StudioTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ abstract public class StudioTest extends AssertJSwingJUnitTestCase {
protected StudioWindow studioWindow;

private static Path tmpConfigFolder;
private int expectedNumberOfErrors;

@BeforeClass
public static void initLogErrors() {
Expand Down Expand Up @@ -82,8 +83,13 @@ public static void setupEmergency() {

}

protected void setExpectedNumberOfLogErrors(int count) {
expectedNumberOfErrors = count;
}

@Override
protected void onSetUp() {
expectedNumberOfErrors = 0;
LogErrors.reset();

studio.ui.I18n.setLocale(Locale.getDefault());
Expand All @@ -98,8 +104,9 @@ protected void onTearDown() throws Exception {
super.onTearDown();

String[] errors = LogErrors.get();
if (errors.length > 0) {
fail("Error logs were detected:\n" + String.join("\n", errors));
if (errors.length != expectedNumberOfErrors) {
fail("There were " + errors.length + " errors instead of expected number: " + expectedNumberOfErrors + "\n"
+ String.join("\n", errors));
}
}

Expand Down
18 changes: 18 additions & 0 deletions test/kx/IPCTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kx;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class IPCTest {

@Test
public void errorDeserilisation() {
byte[] data = new byte[] {-128, 116, 121, 112, 101, 0};
KMessage message = IPC.deserialise(data, false, true);

assertTrue(message.getError() instanceof K4Exception);
assertEquals("'type", message.getError().getMessage());
}
}

0 comments on commit 3f9e3e6

Please sign in to comment.