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

feat: display errors in CLI in red text #4509

Merged
merged 3 commits into from Feb 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion ksql-cli/src/main/java/io/confluent/ksql/cli/Cli.java
Expand Up @@ -175,7 +175,8 @@ public void runInteractively() {
eof = true;
} catch (final Exception exception) {
LOGGER.error("", exception);
terminal.writer().println(ErrorMessageUtil.buildErrorMessage(exception));
terminal.printError(ErrorMessageUtil.buildErrorMessage(exception),
exception.toString());
}
terminal.flush();
}
Expand Down
Expand Up @@ -322,7 +322,7 @@ public void printErrorMessage(final KsqlErrorMessage errorMessage) {

public void printError(final String shortMsg, final String fullMsg) {
log.error(fullMsg);
writer().println(shortMsg);
terminal.printError(shortMsg);
}

public void printStreamedRow(final StreamedRow row) {
Expand Down
Expand Up @@ -153,6 +153,13 @@ public StatusClosable setStatusMessage(final String message) {
return () -> updateStatusBar(DEFAULT_STATUS_MSG);
}

@Override
public void printError(final String message) {
writer().println(
new AttributedString(message, AttributedStyle.DEFAULT.foreground(AttributedStyle.RED))
.toAnsi());
}

@VisibleForTesting
Terminal getTerminal() {
return terminal;
Expand Down
Expand Up @@ -45,6 +45,7 @@ public interface KsqlTerminal {
@FunctionalInterface
interface StatusClosable extends Closeable {

@Override
void close();
}

Expand All @@ -58,6 +59,8 @@ interface StatusClosable extends Closeable {
*/
StatusClosable setStatusMessage(String message);

void printError(String message);

void close();

class HistoryEntry {
Expand Down
Expand Up @@ -16,7 +16,6 @@
package io.confluent.ksql;

import io.confluent.ksql.cli.console.KsqlTerminal;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
Expand Down Expand Up @@ -95,4 +94,9 @@ public void unsetSpool() {
public StatusClosable setStatusMessage(final String message) {
return () -> {};
}

@Override
public void printError(final String message) {
writer().println(message);
}
}