Skip to content

Commit

Permalink
[SQLLINE-224] Print exception traces only in case of verbose on
Browse files Browse the repository at this point in the history
  • Loading branch information
snuyanzin authored and julianhyde committed Jan 9, 2019
1 parent e04bb9c commit e853fe4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/main/java/sqlline/SqlLineOpts.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,13 @@ public void set(SqlLineProperty key, Object value) {
valueToSet = value instanceof Integer || value.getClass() == int.class
? value : Integer.parseInt(String.valueOf(value));
} catch (Exception e) {
sqlLine.error(sqlLine.loc("not-a-number"));
sqlLine.handleException(e);
sqlLine.error(
sqlLine.loc("not-a-number",
key.propertyName().toLowerCase(Locale.ROOT),
value));
if (getVerbose()) {
sqlLine.handleException(e);
}
return;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/sqlline/SqlLine.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ no-specified-prop: Specified property [{0}] does not exist. \
Use !set command to get list of all available properties.
reset-all-props: All properties were reset to their defaults.
reset-prop: [{0}] was reset to [{1}]
not-a-number: "Value should be a number"
not-a-number: Value for property {0} should be a number. Specified value is: {1}.

jdbc-level: JDBC level
compliant: Compliant
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/sqlline/PromptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void testPromptWithNickname() {
ByteArrayOutputStream os = new ByteArrayOutputStream();
SqlLine sqlLine = new SqlLine();
try {
SqlLine.Status status =
final SqlLine.Status status =
begin(sqlLine, os, false, "-e", "!set maxwidth 80");
assertThat(status, equalTo(SqlLine.Status.OK));
final DispatchCallback dc = new DispatchCallback();
Expand Down Expand Up @@ -149,7 +149,7 @@ public void testPromptWithConnection() {
ByteArrayOutputStream os = new ByteArrayOutputStream();
SqlLine sqlLine = new SqlLine();
try {
SqlLine.Status status =
final SqlLine.Status status =
begin(sqlLine, os, false, "-e", "!set maxwidth 80");
assertThat(status, equalTo(SqlLine.Status.OK));
final DispatchCallback dc = new DispatchCallback();
Expand Down
12 changes: 5 additions & 7 deletions src/test/java/sqlline/SqlLineArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public SqlLineArgsTest() {
connectionSpec = CONNECTION_SPEC;
}

static SqlLine.Status begin(
SqlLine sqlLine, OutputStream os, boolean saveHistory, String... args) {
static SqlLine.Status begin(SqlLine sqlLine, OutputStream os,
boolean saveHistory, String... args) {
try {
PrintStream beelineOutputStream = getPrintStream(os);
sqlLine.setOutputStream(beelineOutputStream);
Expand Down Expand Up @@ -509,9 +509,7 @@ public void testManual() {
new MockUp<Commands>() {
@Mock
void less(Terminal terminal, InputStream in, PrintStream out,
PrintStream err,
Path currentDir,
String[] argv) {
PrintStream err, Path currentDir, String[] argv) {
}
};

Expand Down Expand Up @@ -1092,11 +1090,11 @@ public void testSetNonIntValuesToIntProperties() {
SqlLine sqlLine = new SqlLine();
final String headerIntervalScript = "!set headerinterval abc\n";
checkScriptFile(headerIntervalScript, false, equalTo(SqlLine.Status.OK),
containsString(sqlLine.loc("not-a-number")));
containsString(sqlLine.loc("not-a-number", "headerinterval", "abc")));

final String rowLimitScript = "!set rowlimit xxx\n";
checkScriptFile(rowLimitScript, false, equalTo(SqlLine.Status.OK),
containsString(sqlLine.loc("not-a-number")));
containsString(sqlLine.loc("not-a-number", "rowlimit", "xxx")));
}

@Test
Expand Down

0 comments on commit e853fe4

Please sign in to comment.