coliver 2003/03/16 20:29:48
Modified: src/java/org/apache/cocoon/components/flow/javascript
JavaScriptInterpreter.java
Log:
attempt to get JS file/line number in stack trace as well as log file
Revision Changes Path
1.6 +24 -9
cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java
Index: JavaScriptInterpreter.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JavaScriptInterpreter.java 17 Mar 2003 00:38:39 -0000 1.5
+++ JavaScriptInterpreter.java 17 Mar 2003 04:29:48 -0000 1.6
@@ -56,6 +56,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
@@ -542,19 +543,21 @@
NativeArray funArgsArray = new NativeArray(funArgs);
Object fun = ScriptableObject.getProperty(thrScope, funName);
if (fun == Scriptable.NOT_FOUND) {
- fun = "funName";
+ fun = "funName"; // this will produce a better error message
}
Object callFunArgs[] = { fun, funArgsArray };
Object callFun = ScriptableObject.getProperty(thrScope, "callFunction");
if (callFun == Scriptable.NOT_FOUND) {
- callFun = "callFunction";
+ callFun = "callFunction"; // this will produce a better error
message
}
ScriptRuntime.call(context, callFun, thrScope, callFunArgs, thrScope);
}
catch (JavaScriptException ex) {
-
Context.reportError(ToolErrorReporter.getMessage("msg.uncaughtJSException",
- ex.getMessage()));
- throw ex;
+ EvaluatorException ee =
+
Context.reportRuntimeError(ToolErrorReporter.getMessage("msg.uncaughtJSException",
+
+
ex.getMessage()));
+ throw new CascadingRuntimeException(ee.getMessage(), unwrap(ex));
}
finally {
exitContext(thrScope);
@@ -620,11 +623,23 @@
try {
((Function)handleContFunction).call(context, kScope, kScope, args);
} catch (JavaScriptException ex) {
-
Context.reportError(ToolErrorReporter.getMessage("msg.uncaughtJSException",
- ex.getMessage()));
- throw ex;
+ EvaluatorException ee =
+
Context.reportRuntimeError(ToolErrorReporter.getMessage("msg.uncaughtJSException",
+
ex.getMessage()));
+ throw new CascadingRuntimeException(ee.getMessage(), unwrap(ex));
} finally {
Context.exit();
}
+ }
+
+ private Throwable unwrap(JavaScriptException e) {
+ Object value = e.getValue();
+ while (value instanceof Wrapper) {
+ value = ((Wrapper)value).unwrap();
+ }
+ if (value instanceof Throwable) {
+ return (Throwable)value;
+ }
+ return e;
}
}