commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject commons-scxml git commit: SCXML-258 align JEXL and Javascript evaluator error handling with the Groovy evaluator error handling
Date Sun, 10 Dec 2017 03:12:17 GMT
Repository: commons-scxml
Updated Branches:
  refs/heads/master 877289e1c -> 5155f49df


SCXML-258 align JEXL and Javascript evaluator error handling with the Groovy evaluator error
handling


Project: http://git-wip-us.apache.org/repos/asf/commons-scxml/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-scxml/commit/5155f49d
Tree: http://git-wip-us.apache.org/repos/asf/commons-scxml/tree/5155f49d
Diff: http://git-wip-us.apache.org/repos/asf/commons-scxml/diff/5155f49d

Branch: refs/heads/master
Commit: 5155f49df062171fec0a73480485926c1b428e2c
Parents: 877289e
Author: Ate Douma <ate@apache.org>
Authored: Sun Dec 10 04:12:11 2017 +0100
Committer: Ate Douma <ate@apache.org>
Committed: Sun Dec 10 04:12:11 2017 +0100

----------------------------------------------------------------------
 .../apache/commons/scxml2/env/javascript/JSEvaluator.java | 10 ++++++++--
 .../org/apache/commons/scxml2/env/jexl/JexlEvaluator.java |  5 +++++
 .../commons/scxml2/env/javascript/JSEvaluatorTest.java    |  2 +-
 3 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/5155f49d/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java b/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
index 6686b19..66f829c 100644
--- a/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
+++ b/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
@@ -239,8 +239,9 @@ public class JSEvaluator extends AbstractBaseEvaluator {
             // copy Javascript global variables to SCXML context.
             copyJavascriptGlobalsToScxmlContext(scriptContext.getBindings(ScriptContext.ENGINE_SCOPE),
effectiveContext);
             return ret;
-        } catch (Exception x) {
-            throw new SCXMLExpressionException("Error evaluating ['" + expression + "'] "
+ x);
+        } catch (Exception e) {
+            String exMessage = e.getMessage() != null ? e.getMessage() : e.getClass().getCanonicalName();
+            throw new SCXMLExpressionException("eval('" + expression + "'): " + exMessage,
e);
         }
     }
 
@@ -268,6 +269,11 @@ public class JSEvaluator extends AbstractBaseEvaluator {
         try {
             ctx.getVars().put(ASSIGN_VARIABLE_NAME, data);
             eval(ctx, sb.toString());
+        } catch (SCXMLExpressionException e) {
+            if (e.getCause() != null && e.getCause() != null && e.getCause().getMessage()
!= null) {
+                throw new SCXMLExpressionException("Error evaluating assign to location=\""
+ location + "\": " + e.getCause().getMessage());
+            }
+            throw e;
         } finally {
             ctx.getVars().remove(ASSIGN_VARIABLE_NAME);
         }

http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/5155f49d/src/main/java/org/apache/commons/scxml2/env/jexl/JexlEvaluator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/scxml2/env/jexl/JexlEvaluator.java b/src/main/java/org/apache/commons/scxml2/env/jexl/JexlEvaluator.java
index 139446a..5ff6440 100644
--- a/src/main/java/org/apache/commons/scxml2/env/jexl/JexlEvaluator.java
+++ b/src/main/java/org/apache/commons/scxml2/env/jexl/JexlEvaluator.java
@@ -188,6 +188,11 @@ public class JexlEvaluator extends AbstractBaseEvaluator {
         try {
             ctx.getVars().put(ASSIGN_VARIABLE_NAME, data);
             eval(ctx, sb.toString());
+        } catch (SCXMLExpressionException e) {
+            if (e.getCause() != null && e.getCause() != null && e.getCause().getMessage()
!= null) {
+                throw new SCXMLExpressionException("Error evaluating assign to location=\""
+ location + "\": " + e.getCause().getMessage());
+            }
+            throw e;
         }
         finally {
             ctx.getVars().remove(ASSIGN_VARIABLE_NAME);

http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/5155f49d/src/test/java/org/apache/commons/scxml2/env/javascript/JSEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/scxml2/env/javascript/JSEvaluatorTest.java b/src/test/java/org/apache/commons/scxml2/env/javascript/JSEvaluatorTest.java
index e898b9c..9ef6b14 100644
--- a/src/test/java/org/apache/commons/scxml2/env/javascript/JSEvaluatorTest.java
+++ b/src/test/java/org/apache/commons/scxml2/env/javascript/JSEvaluatorTest.java
@@ -172,7 +172,7 @@ public class JSEvaluatorTest {
 
         } catch (SCXMLExpressionException x) {
             Assert.assertTrue("JSEvaluator: Incorrect error message",
-                       x.getMessage().startsWith("Error evaluating ['" + BAD_EXPRESSION +
"']"));
+                       x.getMessage().startsWith("eval('" + BAD_EXPRESSION + "')"));
         }
     }
 


Mime
View raw message