Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compile error message #17822

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ public void compile(Set<File> filesToCompile, Context context) {
compilerFlags.toList(), null, sources);

if (!task.call()) {
throw new RuntimeException("Compilation failed" + diagnostics.getDiagnostics());
StringBuilder sb = new StringBuilder("\u001B[91mCompilation Failed:");
for (Diagnostic<? extends JavaFileObject> i : diagnostics.getDiagnostics()) {
sb.append("\n");
sb.append(i.toString());
}
sb.append("\u001b[0m");
throw new RuntimeException(sb.toString());
}

logDiagnostics(diagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class AeshConsole extends QuarkusConsole {
private String promptMessage;
private int totalStatusLines = 0;
private int lastWriteCursorX;
/**
* if the status area has gotten big then small again
* this tracks how many lines of blank space we have
* so we start writing in the correct place.
*/
private int bottomBlankSpace = 0;
/**
* The write queue
* <p>
Expand Down Expand Up @@ -68,20 +74,33 @@ private AeshConsole setStatusMessage(String statusMessage) {
} else {
newLines += 3;
}
if (newLines > totalStatusLines) {
for (int i = 0; i < newLines - totalStatusLines; ++i) {
buffer.append("\n");
}
}
this.statusMessage = statusMessage;
this.totalStatusLines = newLines;
printStatusAndPrompt(buffer);
writeQueue.add(buffer.toString());
updatePromptOnChange(buffer, newLines);
}
deadlockSafeWrite();
return this;
}

private void updatePromptOnChange(StringBuilder buffer, int newLines) {
if (newLines > totalStatusLines) {
StringBuilder nb = new StringBuilder();
for (int i = 0; i < newLines - totalStatusLines; ++i) {
if (bottomBlankSpace > 0) {
bottomBlankSpace--;
} else {
nb.append("\n");
}
}
writeQueue.add(nb.toString());
deadlockSafeWrite();
} else if (newLines < totalStatusLines) {
bottomBlankSpace = bottomBlankSpace + (totalStatusLines - newLines);
}
this.totalStatusLines = newLines;
printStatusAndPrompt(buffer);
writeQueue.add(buffer.toString());
}

public AeshInputHolder createHolder(InputHandler inputHandler) {
return new AeshInputHolder(inputHandler);
}
Expand All @@ -103,15 +122,8 @@ private AeshConsole setPromptMessage(String promptMessage) {
} else {
newLines += 3;
}
if (newLines > totalStatusLines) {
for (int i = 0; i < newLines - totalStatusLines; ++i) {
buffer.append("\n");
}
}
this.promptMessage = promptMessage;
this.totalStatusLines = newLines;
printStatusAndPrompt(buffer);
writeQueue.add(buffer.toString());
updatePromptOnChange(buffer, newLines);
}
deadlockSafeWrite();
return this;
Expand Down Expand Up @@ -207,10 +219,13 @@ public void run() {
private void printStatusAndPrompt(StringBuilder buffer) {
if (totalStatusLines == 0) {
return;
} else if (totalStatusLines < size.getHeight()) {
//if the console is tiny we don't do this
clearStatusMessages(buffer);
gotoLine(buffer, size.getHeight() - totalStatusLines);
} else {
bottomBlankSpace = 0;
}

clearStatusMessages(buffer);
gotoLine(buffer, size.getHeight() - totalStatusLines);
buffer.append("\n--\n");
if (statusMessage != null) {
buffer.append(statusMessage);
Expand Down Expand Up @@ -267,11 +282,11 @@ public void write(String s) {
}
}
if (totalStatusLines == 0) {
bottomBlankSpace = 0; //just to be safe, will only happen if status is added then removed, which is not really likely
writeQueue.add(s);
} else {
clearStatusMessages(buffer);
int cursorPos = lastWriteCursorX;
gotoLine(buffer, size.getHeight());
String stripped = stripAnsiCodes(s);
int lines = countLines(s, cursorPos);
int trailing = 0;
Expand All @@ -288,29 +303,38 @@ public void write(String s) {
} else {
newCursorPos = trailing;
}

int usedBlankSpace = 0;
gotoLine(buffer, size.getHeight());
if (cursorPos > 1 && lines == 0) {
gotoLine(buffer, size.getHeight() - bottomBlankSpace);
buffer.append(s);
lastWriteCursorX = newCursorPos;
//partial line, just write it
connection.write(buffer.toString());
return;
}
if (lines == 0) {
lines++;
}
//move the existing content up by the number of lines
int appendLines = Math.max(Math.min(cursorPos > 1 ? lines - 1 : lines, totalStatusLines), 1);
clearStatusMessages(buffer);
buffer.append("\033[").append(size.getHeight() - totalStatusLines).append(";").append(0).append("H");
buffer.append(s);
buffer.append("\033[").append(size.getHeight()).append(";").append(0).append("H");
for (int i = 0; i < appendLines; ++i) {
buffer.append("\n");
writeQueue.add(buffer.toString());
} else {
if (lines == 0) {
lines++;
}
int originalBlank = bottomBlankSpace;
if (bottomBlankSpace > 0) {
usedBlankSpace = Math.min(bottomBlankSpace, lines);
bottomBlankSpace -= usedBlankSpace;
}
//move the existing content up by the number of lines
int appendLines = Math.max(Math.min(cursorPos > 1 ? lines - 1 : lines, totalStatusLines), 1);
appendLines -= usedBlankSpace;
clearStatusMessages(buffer);
buffer.append("\033[").append(size.getHeight() - totalStatusLines - originalBlank).append(";").append(0)
.append("H");
buffer.append(s);
buffer.append("\033[").append(size.getHeight()).append(";").append(0).append("H");
for (int i = 0; i < appendLines; ++i) {
buffer.append("\n");
}
lastWriteCursorX = newCursorPos;
printStatusAndPrompt(buffer);
writeQueue.add(buffer.toString());
}
lastWriteCursorX = newCursorPos;
printStatusAndPrompt(buffer);
writeQueue.add(buffer.toString());
}
}
deadlockSafeWrite();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public void testsDisabled() {
promptHandler.setStatus(null);
}

@Override
public void testCompileFailed(String message) {
promptHandler.setStatus(message);
}

@Override
public void testRunStarted(Consumer<TestRunListener> listenerConsumer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ default void setTestOutput(boolean to) {
default void setInstrumentationBasedReload(boolean ibr) {

}

default void testCompileFailed(String message) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

public class TestRunner {

private static final Logger log = Logger.getLogger(TestRunner.class);
private static final Logger log = Logger.getLogger("io.quarkus.test");
private static final AtomicLong COUNTER = new AtomicLong();

private final TestSupport testSupport;
Expand Down Expand Up @@ -354,9 +354,14 @@ public void waitTillResumed() {
}
}

public synchronized void testCompileFailed(Throwable e) {
compileProblem = e;
log.error("Test compile failed", e);
public void testCompileFailed(Throwable e) {
synchronized (this) {
compileProblem = e;
}

for (TestListener i : testSupport.testListeners) {
i.testCompileFailed(e.getMessage());
}
}

public synchronized void testCompileSucceeded() {
Expand Down