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

已查看 1 次
跳至第一个未读帖子

Thad Guidry

未读,
2021年9月28日 15:20:242021/9/28
收件人 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

未读,
2021年9月28日 16:43:552021/9/28
收件人 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
回复全部
回复作者
转发
0 个新帖子