How can I print the GREL type() in an EvalError to help the user more?

1 view
Skip to first unread message

Thad Guidry

unread,
Sep 28, 2021, 3:20:24 PMSep 28
to openref...@googlegroups.com
Given something like...

                return new EvalError(ControlFunctionRegistry.getFunctionName(this)
                        + "Not an XML or HTML Element."
                        + " You might have an Array instead where you need to select an index or loop with"
                        + " forEach() over. Check the type with .type() or first use parseXml() or parseHtml()");
            }

I'd like to actually stringify the GREL type (in my use case it would be `array`).
How can I mention what the GREL type is to the user in this EvalError message with string concatenation?  Something like this...

                return new EvalError(ControlFunctionRegistry.getFunctionName(this)
                        + "needs an XML or HTML Element to work, but instead this is a "
+ e1.Type()
                        + ". If an `array` you need to first select an index or loop over them with"
                        + " forEach(). Please first use parseXml() or parseHtml()");
            }

Thoughts?

Thad

Thad Guidry

unread,
Sep 28, 2021, 4:43:55 PMSep 28
to openref...@googlegroups.com
Figured it out with the help of another Java pro/friend.

                return new EvalError(ControlFunctionRegistry.getFunctionName(this)
                        + new Type().call(bindingsargs)
                        + " needs a jsoup XML or HTML Element to work with. Check this first by adding .type()"
                        + " You might have an Array instead where you need to select an index or loop with"
                        + " forEach() over.  Please first use parseXml() or parseHtml()");

            }

image.png

New GREL function forthcoming... jsoup Element's parent()  ISSUE:  https://github.com/OpenRefine/OpenRefine/issues/4181
And works beautifully to traverse up the parent elements in the DOM as necessary whenever a good div class or id is missing where you can't use CSS Selector syntax.
And both CSS select() and DOM parent() can work in combination.  Here I get the parent of a parent of the CSS select() Element found...

image.png
Reply all
Reply to author
Forward
0 new messages