Revision: 6345 Author: [email protected] Date: Sat Oct 10 13:50:54 2009 Log: Improve error reporting inside of custom at-rules.
Patch by: bobv Review by: rjrjr http://code.google.com/p/google-web-toolkit/source/detail?r=6345 Modified: /trunk/user/src/com/google/gwt/resources/css/GenerateCssAst.java ======================================= --- /trunk/user/src/com/google/gwt/resources/css/GenerateCssAst.java Sat Oct 10 13:50:44 2009 +++ /trunk/user/src/com/google/gwt/resources/css/GenerateCssAst.java Sat Oct 10 13:50:54 2009 @@ -109,6 +109,14 @@ public Errors(TreeLogger parentLogger) { this.parentLogger = parentLogger; } + + public TreeLogger branch(TreeLogger.Type type, String message) { + return branch(type, message, null); + } + + public TreeLogger branch(TreeLogger.Type type, String message, Throwable t) { + return logOrBranch(type, message, t, true); + } public void error(CSSParseException exception) throws CSSException { // TODO Since this indicates a loss of data, should this be a fatal error? @@ -124,11 +132,7 @@ } public void log(TreeLogger.Type type, String message, Throwable t) { - fatalErrorEncountered |= type == TreeLogger.Type.ERROR; - if (parentLogger.isLoggable(type)) { - maybeBranch(); - logger.log(type, message, t); - } + logOrBranch(type, message, t, false); } public void warning(CSSParseException exception) throws CSSException { @@ -139,6 +143,22 @@ log(type, "Line " + e.getLineNumber() + " column " + e.getColumnNumber() + ": " + e.getMessage()); } + + private TreeLogger logOrBranch(TreeLogger.Type type, String message, + Throwable t, boolean branch) { + fatalErrorEncountered |= type == TreeLogger.Type.ERROR; + if (parentLogger.isLoggable(type)) { + maybeBranch(); + if (branch) { + return logger.branch(type, message, t); + } else { + logger.log(type, message, t); + return null; + } + } else { + return TreeLogger.NULL; + } + } private void maybeBranch() { if (logger == null) { @@ -225,11 +245,21 @@ } catch (IllegalAccessException e) { errors.log(TreeLogger.ERROR, "Unable to invoke parse method ", e); } catch (InvocationTargetException e) { - if (e.getCause() instanceof CSSException) { - throw (CSSException) e.getCause(); - } - - errors.log(TreeLogger.ERROR, "Unable to invoke parse method ", e); + Throwable cause = e.getCause(); + + if (cause instanceof CSSException) { + // Unwind a CSSException normally + throw (CSSException) cause; + } else if (cause != null) { + // Otherwise, report the message nicely + TreeLogger details = errors.branch(TreeLogger.ERROR, + cause.getMessage()); + details.log(TreeLogger.DEBUG, "Full stack trace", cause); + } else { + TreeLogger details = errors.branch(TreeLogger.ERROR, + "Unknown failure parsing " + ruleName); + details.log(TreeLogger.DEBUG, "Full stack trace", e); + } } } --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
