Skip to content

Commit

Permalink
Resolution of bug 2996883 - Misleading warning messages when invalid …
Browse files Browse the repository at this point in the history
…regular expressions are specified
  • Loading branch information
johncurrier committed May 5, 2010
1 parent fbda39c commit f32d4e0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
5 changes: 5 additions & 0 deletions dist/releaseNotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ <h3><a href='http://schemaspy.sourceforge.net'>SchemaSpy</a> Release Notes</h3>
<a href='https://sourceforge.net/projects/schemaspy/forums/forum/462849/topic/3586068'>
Jonas Söderström's suggestion</a>.
</li>
<li>Resolved <a href="https://sourceforge.net/tracker/?func=detail&atid=737987&aid=2996883&group_id=137197">
bug 2996883</a> - Misleading warning messages when invalid regular expressions
are specified.<br>
Thanks to David Corlette for reporting the problem.
</li>
</ul>
</li>

Expand Down
41 changes: 34 additions & 7 deletions src/net/sourceforge/schemaspy/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import net.sourceforge.schemaspy.model.InvalidConfigurationException;
import net.sourceforge.schemaspy.util.DbSpecificConfig;
import net.sourceforge.schemaspy.util.Dot;
Expand Down Expand Up @@ -624,7 +625,8 @@ public int getMaxDbThreads() throws InvalidConfigurationException {
try {
properties = getDbProperties(getDbType());
} catch (IOException exc) {
throw new InvalidConfigurationException("Failed to load properties for " + getDbType() + ": " + exc);
throw new InvalidConfigurationException("Failed to load properties for " + getDbType() + ": " + exc)
.setParamName("-type");
}

int max = Integer.MAX_VALUE;
Expand Down Expand Up @@ -849,7 +851,11 @@ public Pattern getTableInclusions() {
if (strInclusions == null)
strInclusions = ".*"; // match anything

tableInclusions = Pattern.compile(strInclusions);
try {
tableInclusions = Pattern.compile(strInclusions);
} catch (PatternSyntaxException badPattern) {
throw new InvalidConfigurationException(badPattern).setParamName("-i");
}
}

return tableInclusions;
Expand All @@ -874,7 +880,11 @@ public Pattern getTableExclusions() {
if (strExclusions == null)
strExclusions = ""; // match nothing

tableExclusions = Pattern.compile(strExclusions);
try {
tableExclusions = Pattern.compile(strExclusions);
} catch (PatternSyntaxException badPattern) {
throw new InvalidConfigurationException(badPattern).setParamName("-I");
}
}

return tableExclusions;
Expand Down Expand Up @@ -945,7 +955,8 @@ public SqlFormatter getSqlFormatter() throws InvalidConfigurationException {
Class<SqlFormatter> clazz = (Class<SqlFormatter>)Class.forName(sqlFormatterClass);
sqlFormatter = clazz.newInstance();
} catch (Exception exc) {
throw new InvalidConfigurationException("Failed to initialize instance of " + sqlFormatterClass, exc);
throw new InvalidConfigurationException("Failed to initialize instance of SQL formatter: ", exc)
.setParamName("-sqlFormatter");
}
}

Expand Down Expand Up @@ -1195,7 +1206,17 @@ public List<String> getRemainingParameters()
{
try {
populate();
} catch (Exception exc) {}
} catch (IllegalArgumentException exc) {
throw new InvalidConfigurationException(exc);
} catch (IllegalAccessException exc) {
throw new InvalidConfigurationException(exc);
} catch (InvocationTargetException exc) {
if (exc.getCause() instanceof InvalidConfigurationException)
throw (InvalidConfigurationException)exc.getCause();
throw new InvalidConfigurationException(exc.getCause());
} catch (IntrospectionException exc) {
throw new InvalidConfigurationException(exc);
}

return options;
}
Expand Down Expand Up @@ -1282,7 +1303,10 @@ public MissingRequiredParameterException(String paramId, boolean dbTypeSpecific)
}

public MissingRequiredParameterException(String paramId, String description, boolean dbTypeSpecific) {
super("Parameter '" + paramId + "' " + (description == null ? "" : "(" + description + ") ") + "missing." + (dbTypeSpecific ? " It is required for this database type." : ""));
super("Required parameter '" + paramId + "' " +
(description == null ? "" : "(" + description + ") ") +
"was not specified." +
(dbTypeSpecific ? " It is required for this database type." : ""));
this.dbTypeSpecific = dbTypeSpecific;
}

Expand Down Expand Up @@ -1378,10 +1402,13 @@ public static Set<String> getBuiltInDatabaseTypes(String loadedFromJar) {

protected void dumpUsage(String errorMessage, boolean detailedDb) {
if (errorMessage != null) {
System.out.flush();
System.err.println("*** " + errorMessage + " ***");
} else {
System.out.println("SchemaSpy generates an HTML representation of a database schema's relationships.");
}

System.out.println("SchemaSpy generates an HTML representation of a database schema's relationships.");
System.err.flush();
System.out.println();

if (!detailedDb) {
Expand Down
6 changes: 5 additions & 1 deletion src/net/sourceforge/schemaspy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public static void main(String[] argv) throws Exception {
rc = 2;
} catch (InvalidConfigurationException badConfig) {
System.err.println();
System.err.println(badConfig.getClass().getSimpleName() + ": " + badConfig.getMessage());
if (badConfig.getParamName() != null)
System.err.println("Bad parameter specified for " + badConfig.getParamName());
System.err.println(badConfig.getMessage());
if (badConfig.getCause() != null && !badConfig.getMessage().endsWith(badConfig.getMessage()))
System.err.println(" caused by " + badConfig.getCause().getMessage());
} catch (ProcessExecutionException badLaunch) {
System.err.println(badLaunch.getMessage());
} catch (Exception exc) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package net.sourceforge.schemaspy.model;

/**
* Base class to indicate that there was problem with how SchemaSpy was configured / used.
*
* Base class to indicate that there was problem with how SchemaSpy was configured / used.
*
* @author John Currier
*/
public class InvalidConfigurationException extends RuntimeException {
private static final long serialVersionUID = 1L;
private String paramName;

/**
* When a message is sufficient
*
*
* @param msg
*/
public InvalidConfigurationException(String msg) {
Expand All @@ -20,20 +21,29 @@ public InvalidConfigurationException(String msg) {
/**
* When there's an associated root cause.
* The resultant msg will be a combination of <code>msg</code> and cause's <code>msg</code>.
*
*
* @param msg
* @param cause
*/
public InvalidConfigurationException(String msg, Throwable cause) {
super(msg + " " + cause.getMessage(), cause);
super(msg, cause);
}

/**
* When there are no details other than the root cause
*
*
* @param cause
*/
public InvalidConfigurationException(Throwable cause) {
super(cause);
}

public InvalidConfigurationException setParamName(String paramName) {
this.paramName = paramName;
return this;
}

public String getParamName() {
return paramName;
}
}

0 comments on commit f32d4e0

Please sign in to comment.