Skip to content

Commit

Permalink
MONDRIAN: TUI: Better error messages, support semicolon as statement …
Browse files Browse the repository at this point in the history
…delimiter.

[git-p4: depot-paths = "//open/mondrian/": change = 3131]
  • Loading branch information
ebb committed Feb 3, 2005
1 parent 32e3908 commit be471df
Showing 1 changed file with 44 additions and 31 deletions.
75 changes: 44 additions & 31 deletions src/main/mondrian/tui/CmdRunner.java
Expand Up @@ -62,7 +62,7 @@ public CmdRunner() {
}

void setError(Throwable t) {
this.error = t.toString();
this.error = formatError(t);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
Expand All @@ -75,6 +75,13 @@ void clearError() {
this.stack = null;
}

private String formatError(Throwable mex) {
String message = mex.getMessage();
if (mex.getCause() != null && mex.getCause() != mex)
message = message + "\n" + formatError(mex.getCause());
return message;
}

public static void listPropertyNames(StringBuffer buf) {
for (int i = 0; i < propertyNames.length; i++) {
String propertyName = propertyNames[i];
Expand Down Expand Up @@ -304,13 +311,25 @@ protected void commandLoop(
InputStream in,
boolean interactive) throws IOException {

StringBuffer buf = new StringBuffer(2048);
StringBuffer buf = null;
BufferedReader br = new BufferedReader(new InputStreamReader(in));
boolean inMDXCmd = false;
if (interactive) {
System.out.print(COMMAND_PROMPT_START);
}
String resultString = null;

for(;;) {
if (resultString != null) {
printResults(resultString);
resultString = null;
}
if (interactive) {
if (inMDXCmd)
System.out.print(COMMAND_PROMPT_MID);
else
System.out.print(COMMAND_PROMPT_START);
}
if (!inMDXCmd) {
buf = new StringBuffer(2048);
}
String line = br.readLine();
if (line != null) {
line = line.trim();
Expand All @@ -330,8 +349,6 @@ protected void commandLoop(
// user command.
if (! inMDXCmd) {
String cmd = line;

String resultString = null;
if (cmd.startsWith("help")) {
resultString = executeHelp(cmd);
} else if (cmd.startsWith("set")) {
Expand All @@ -346,12 +363,7 @@ protected void commandLoop(
resultString = executeExit(cmd);
}
if (resultString != null) {
printResults(resultString);
inMDXCmd = false;
buf.setLength(0);
if (interactive) {
System.out.print(COMMAND_PROMPT_START);
}
continue;
}
}
Expand All @@ -368,29 +380,25 @@ protected void commandLoop(
String mdxCmd = buf.toString().trim();
debug("mdxCmd=\""+mdxCmd+"\"");

String resultString = executeMDXCmd(mdxCmd);
if (resultString != null) {
printResults(resultString);
}
resultString = executeMDXCmd(mdxCmd);
}

inMDXCmd = false;
buf.setLength(0);
if (interactive) {
System.out.print(COMMAND_PROMPT_START);
}


} else if (line.length() > 0) {
// OK, just add the line to the mdx query we are building.
inMDXCmd = true;
buf.append(line);
// add carriage return so that query keeps formatting
buf.append('\n');
if (interactive) {
System.out.print(COMMAND_PROMPT_MID);
}
if (line.endsWith(";")) {
String mdxCmd = buf.toString().trim();
debug("mdxCmd=\""+mdxCmd+"\"");
resultString = executeMDXCmd(mdxCmd);
inMDXCmd = false;
} else {
// add carriage return so that query keeps formatting
buf.append('\n');
}
}

}
}

Expand Down Expand Up @@ -556,6 +564,12 @@ protected static String executeHelp(String mdxCmd) {
buf.append('\n');
appendIndent(buf, 3);
buf.append("the command interpreter.");
buf.append('\n');
appendIndent(buf, 2);
buf.append("Queries can also be ended by using a semicolon (;)");
buf.append('\n');
appendIndent(buf, 3);
buf.append("at the end of a line.");
}

if ((cmd & ERROR_CMD) != 0) {
Expand Down Expand Up @@ -830,19 +844,18 @@ protected String executeMDXCmd(String mdxCmd) {
this.mdxCmd = mdxCmd;
try {

String resultString = context.cmdRunner.execute(mdxCmd);
String resultString = execute(mdxCmd);
mdxResult = resultString;
clearError();
return resultString;

} catch (MondrianException mex) {
setError(mex);
return mex.getMessage();
return error;
}
}


/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// context
/////////////////////////////////////////////////////////////////////////
private static class Context {
Expand Down

0 comments on commit be471df

Please sign in to comment.