From 95f11efa4d4dbf80c249a7ba6c71c02219e3903d Mon Sep 17 00:00:00 2001 From: Dorinel Utiu Date: Mon, 4 Dec 2017 14:05:42 +0200 Subject: [PATCH 1/4] trim the python expression in case an error occurs --- .../bindings/scripts/ScriptEvaluator.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java index 22c29018b9..e3e8605b2f 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java @@ -16,17 +16,18 @@ import io.cloudslang.lang.entities.bindings.values.ValueFactory; import io.cloudslang.runtime.api.python.PythonEvaluationResult; import io.cloudslang.runtime.api.python.PythonRuntimeService; -import java.io.Serializable; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; import org.apache.commons.lang3.StringUtils; import org.python.core.Py; import org.python.core.PyObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.io.Serializable; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + /** * @author stoneo * @version $Id$ @@ -48,6 +49,8 @@ public class ScriptEvaluator extends ScriptProcessor { "def check_empty(value_to_check, default_value=None):" + LINE_SEPARATOR + " return default_value if value_to_check is None else value_to_check"; + public static final int MAX_LENGTH = Integer.getInteger("input.error.max.length", 1000); + @Autowired private PythonRuntimeService pythonRuntimeService; @@ -68,8 +71,9 @@ public Value evalExpr(String expr, Map context, Set MAX_LENGTH ? expr.substring(0, MAX_LENGTH) + "..." : expr; throw new RuntimeException("Error in running script expression: '" + - expr + "',\n\tException is: " + + exprSubstring + "',\n\tException is: " + handleExceptionSpecialCases(exception.getMessage()), exception); } } From cd361662f2ecf23df46e96c921c087f5c39efa77 Mon Sep 17 00:00:00 2001 From: Dorinel Utiu Date: Mon, 4 Dec 2017 14:05:42 +0200 Subject: [PATCH 2/4] trim the python expression in case an error occurs Signed-off-by: Dorinel Utiu --- .../bindings/scripts/ScriptEvaluator.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java index 22c29018b9..e3e8605b2f 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java @@ -16,17 +16,18 @@ import io.cloudslang.lang.entities.bindings.values.ValueFactory; import io.cloudslang.runtime.api.python.PythonEvaluationResult; import io.cloudslang.runtime.api.python.PythonRuntimeService; -import java.io.Serializable; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; import org.apache.commons.lang3.StringUtils; import org.python.core.Py; import org.python.core.PyObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.io.Serializable; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + /** * @author stoneo * @version $Id$ @@ -48,6 +49,8 @@ public class ScriptEvaluator extends ScriptProcessor { "def check_empty(value_to_check, default_value=None):" + LINE_SEPARATOR + " return default_value if value_to_check is None else value_to_check"; + public static final int MAX_LENGTH = Integer.getInteger("input.error.max.length", 1000); + @Autowired private PythonRuntimeService pythonRuntimeService; @@ -68,8 +71,9 @@ public Value evalExpr(String expr, Map context, Set MAX_LENGTH ? expr.substring(0, MAX_LENGTH) + "..." : expr; throw new RuntimeException("Error in running script expression: '" + - expr + "',\n\tException is: " + + exprSubstring + "',\n\tException is: " + handleExceptionSpecialCases(exception.getMessage()), exception); } } From e38b3fc0b2554e5eecc2e9a044de992d65b8345a Mon Sep 17 00:00:00 2001 From: Dorinel Utiu Date: Thu, 4 Jan 2018 10:47:59 +0200 Subject: [PATCH 3/4] extract in a method the truncation of the python expression --- .../lang/runtime/bindings/scripts/ScriptEvaluator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java index e3e8605b2f..3160d9623b 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java @@ -71,13 +71,16 @@ public Value evalExpr(String expr, Map context, Set MAX_LENGTH ? expr.substring(0, MAX_LENGTH) + "..." : expr; throw new RuntimeException("Error in running script expression: '" + - exprSubstring + "',\n\tException is: " + + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.getMessage()), exception); } } + private String getTruncatedExpression(String expr) { + return expr.length() > MAX_LENGTH ? expr.substring(0, MAX_LENGTH) + "..." : expr; + } + private String buildAddFunctionsScript(Set functionDependencies) { String functions = ""; for (ScriptFunction function : functionDependencies) { From cc16a5ea2d506ca7c9bb484439622660a822ef0f Mon Sep 17 00:00:00 2001 From: Dorinel Utiu Date: Mon, 8 Jan 2018 16:14:53 +0200 Subject: [PATCH 4/4] score 0.3.47 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0da4de9b37..f0f1f1fabd 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ UTF-8 UTF-8 io.cloudslang - 0.3.46 + 0.3.47 4.3.10.RELEASE 2.10 2.8