diff --git a/main/src/com/google/refine/expr/functions/html/InnerHtml.java b/main/src/com/google/refine/expr/functions/html/InnerHtml.java index 63cd9cc13..74f051147 100644 --- a/main/src/com/google/refine/expr/functions/html/InnerHtml.java +++ b/main/src/com/google/refine/expr/functions/html/InnerHtml.java @@ -38,6 +38,7 @@ import java.util.Properties; import org.jsoup.nodes.Element; import com.google.refine.expr.EvalError; +import com.google.refine.expr.functions.Type; import com.google.refine.expr.functions.xml.InnerXml; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -51,10 +52,10 @@ public class InnerHtml implements Function { if (o1 != null && o1 instanceof Element) { return new InnerXml().call(bindings, args, "html"); }else{ - return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " failed as the first parameter is not an HTML Element. Please first use parseHtml(string) and select(query) prior to using this function"); + return new EvalError(ControlFunctionRegistry.getFunctionName(this) + "() cannot work with this '" + new Type().call(bindings, args) + "'. The first parameter is not an HTML Element. Please first use parseHtml(string) and select(query) prior to using this function"); } } - return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a single String as an argument"); + return new EvalError(ControlFunctionRegistry.getFunctionName(this) + "() cannot work with this '" + new Type().call(bindings, args) + "' and expects a single String as an argument"); } diff --git a/main/src/com/google/refine/expr/functions/html/ParseHtml.java b/main/src/com/google/refine/expr/functions/html/ParseHtml.java index cc6de672a..0e442b00c 100644 --- a/main/src/com/google/refine/expr/functions/html/ParseHtml.java +++ b/main/src/com/google/refine/expr/functions/html/ParseHtml.java @@ -36,6 +36,7 @@ package com.google.refine.expr.functions.html; import java.util.Properties; import com.google.refine.expr.EvalError; +import com.google.refine.expr.functions.Type; import com.google.refine.expr.functions.xml.ParseXml; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; diff --git a/main/src/com/google/refine/expr/functions/xml/ParseXml.java b/main/src/com/google/refine/expr/functions/xml/ParseXml.java index 8361bba86..b950ba248 100644 --- a/main/src/com/google/refine/expr/functions/xml/ParseXml.java +++ b/main/src/com/google/refine/expr/functions/xml/ParseXml.java @@ -35,6 +35,7 @@ package com.google.refine.expr.functions.xml; import java.util.Properties; +import com.google.refine.expr.functions.Type; import org.jsoup.Jsoup; import org.jsoup.parser.Parser; diff --git a/main/src/com/google/refine/expr/functions/xml/WholeText.java b/main/src/com/google/refine/expr/functions/xml/WholeText.java index 8dba04283..bb66b268f 100644 --- a/main/src/com/google/refine/expr/functions/xml/WholeText.java +++ b/main/src/com/google/refine/expr/functions/xml/WholeText.java @@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.expr.functions.xml; import java.util.Properties; +import com.google.refine.expr.functions.Type; import org.jsoup.nodes.Element; @@ -52,13 +53,12 @@ public class WholeText implements Function { return e1.wholeText(); }else{ - return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function"); + return new EvalError(ControlFunctionRegistry.getFunctionName(this) + "() cannot work with this '" + new Type().call(bindings, args) + "' and failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function"); } } - return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a single XML or HTML element as an argument"); + return new EvalError(ControlFunctionRegistry.getFunctionName(this) + "() cannot work with this '" + new Type().call(bindings, args) + "' and expects a single XML or HTML element as an argument"); } - @Override public String getDescription() { return "Selects the (unencoded) text of an element and its children, including any new lines and spaces, and returns a string of unencoded, un-normalized text. Use it in conjunction with parseHtml() and select() to provide an element."; diff --git a/main/src/com/google/refine/expr/functions/xml/XmlText.java b/main/src/com/google/refine/expr/functions/xml/XmlText.java index 313491c4e..61df90b42 100644 --- a/main/src/com/google/refine/expr/functions/xml/XmlText.java +++ b/main/src/com/google/refine/expr/functions/xml/XmlText.java @@ -37,6 +37,7 @@ import java.util.Properties; import org.jsoup.nodes.Element; +import com.google.refine.expr.functions.Type; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -52,10 +53,10 @@ public class XmlText implements Function { return e1.text(); }else{ - return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function"); + return new EvalError(ControlFunctionRegistry.getFunctionName(this) + "() cannot work with this '" + new Type().call(bindings, args) + "' and failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function"); } } - return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a single XML or HTML element as an argument"); + return new EvalError(ControlFunctionRegistry.getFunctionName(this) + "() cannot work with this '" + new Type().call(bindings, args) + "' and expects a single XML or HTML element as an argument"); } diff --git a/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java b/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java index 3b8b5ed86..8ac1ac714 100644 --- a/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java +++ b/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java @@ -26,14 +26,53 @@ ******************************************************************************/ package com.google.refine.expr; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.refine.expr.EvalError; +import com.google.refine.RefineTest; import com.google.refine.util.TestUtils; -public class EvalErrorTests { +public class EvalErrorTests extends RefineTest { + + @Override + @BeforeTest + public void init() { + logger = LoggerFactory.getLogger(this.getClass()); + } + @Test public void serializeEvalError() { EvalError e = new EvalError("This is a critical error"); TestUtils.isSerializedTo(e, "{\"type\":\"error\",\"message\":\"This is a critical error\"}"); } + + @Test + public void testInnerHtml() { + Assert.assertTrue(invoke("innerHtml") instanceof EvalError); + Assert.assertTrue(invoke("innerHtml", "test") instanceof EvalError); + + EvalError evalError = (EvalError) invoke("innerHtml", "test"); + Assert.assertEquals(evalError.toString(), "innerHtml() cannot work with this \'string\'. The first parameter is not an HTML Element. Please first use parseHtml(string) and select(query) prior to using this function"); + } + + @Test + public void testWholeText() { + Assert.assertTrue(invoke("wholeText") instanceof EvalError); + Assert.assertTrue(invoke("wholeText", "test") instanceof EvalError); + + EvalError evalError = (EvalError) invoke("wholeText", "test"); + Assert.assertEquals(evalError.toString(), "wholeText() cannot work with this \'string\' and failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function"); + } + + @Test + public void testXmlText() { + Assert.assertTrue(invoke("xmlText") instanceof EvalError); + Assert.assertTrue(invoke("xmlText", "test") instanceof EvalError); + + EvalError evalError = (EvalError) invoke("xmlText", "test"); + Assert.assertEquals(evalError.toString(), "xmlText() cannot work with this \'string\' and failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function"); + } }