You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by by...@apache.org on 2009/01/30 20:54:17 UTC
svn commit: r739393 - in
/velocity/engine/trunk/src/java/org/apache/velocity/runtime:
directive/Block.java directive/RuntimeMacro.java
parser/node/ASTReference.java
Author: byron
Date: Fri Jan 30 19:54:17 2009
New Revision: 739393
URL: http://svn.apache.org/viewvc?rev=739393&view=rev
Log:
Change block error messages to standard location format. Improve error logging when blocks generate exceptions. Add the call location to our sudo error log stack
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Block.java
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Block.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Block.java?rev=739393&r1=739392&r2=739393&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Block.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Block.java Fri Jan 30 19:54:17 2009
@@ -48,7 +48,6 @@
protected Node block;
protected Log log;
protected int maxDepth;
- protected String definingTemplate;
protected String key;
/**
@@ -74,11 +73,6 @@
* that it's the block!
*/
block = node.jjtGetChild(node.jjtGetNumChildren() - 1);
-
- /**
- * keep tabs on the template this came from
- */
- definingTemplate = context.getCurrentTemplateName();
}
/**
@@ -89,12 +83,8 @@
protected String id(InternalContextAdapter context)
{
StrBuilder str = new StrBuilder(100)
- .append("block $").append(key)
- .append(" (defined in ").append(definingTemplate)
- .append(" [line ").append(getLine())
- .append(", column ").append(getColumn()).append("])");
-
- if (!context.getCurrentTemplateName().equals(definingTemplate))
+ .append("block $").append(key);
+ if (!context.getCurrentTemplateName().equals(getTemplateName()))
{
str.append(" used in ").append(context.getCurrentTemplateName());
}
@@ -135,7 +125,8 @@
* use recursive block definitions and having problems
* pulling it off properly.
*/
- parent.log.debug("Max recursion depth reached for "+parent.id(context));
+ parent.log.debug("Max recursion depth reached for " + parent.id(context)
+ + " at " + Log.formatFileString(parent));
depth--;
return false;
}
@@ -148,16 +139,12 @@
}
catch (IOException e)
{
- String msg = "Failed to render "+parent.id(context)+" to writer";
+ String msg = "Failed to render " + parent.id(context) + " to writer "
+ + " at " + Log.formatFileString(parent);
+
parent.log.error(msg, e);
throw new RuntimeException(msg, e);
}
- catch (VelocityException ve)
- {
- String msg = "Failed to render "+parent.id(context)+" due to "+ve;
- parent.log.error(msg, ve);
- throw ve;
- }
}
public String toString()
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java?rev=739393&r1=739392&r2=739393&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java Fri Jan 30 19:54:17 2009
@@ -307,13 +307,13 @@
* especially important for multiple macro call levels.
* this is also true for the following catch blocks.
*/
- rsvc.getLog().error("Exception in macro #" + macroName + " at " +
+ rsvc.getLog().error("Exception in macro #" + macroName + " called at " +
Log.formatFileString(node));
throw e;
}
catch (IOException e)
{
- rsvc.getLog().error("Exception in macro #" + macroName + " at " +
+ rsvc.getLog().error("Exception in macro #" + macroName + " called at " +
Log.formatFileString(node));
throw e;
}
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java?rev=739393&r1=739392&r2=739393&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java Fri Jan 30 19:54:17 2009
@@ -29,8 +29,9 @@
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.exception.VelocityException;
-import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.Renderable;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.directive.Block.Reference;
import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.parser.Token;
@@ -394,11 +395,26 @@
String toString = null;
if (value != null)
- {
-
- if(value instanceof Renderable && ((Renderable)value).render(context,writer))
+ {
+ if (value instanceof Renderable)
{
- return true;
+ Renderable renderable = (Renderable)value;
+ try
+ {
+ if (renderable.render(context,writer))
+ return true;
+ }
+ catch(RuntimeException e)
+ {
+ // We commonly get here when an error occurs within a block reference.
+ // We want to log where the reference is at so that a developer can easily
+ // know where the offending call is located. This can be seen
+ // as another element of the error stack we report to log.
+ log.error("Exception rendering "
+ + ((renderable instanceof Reference)? "block ":"Renderable ")
+ + rootString + " at " + Log.formatFileString(this));
+ throw e;
+ }
}
toString = value.toString();