Scott R. Turner - 2013-02-16

I'm trying to use WH2.1 and I have a chunk of config that looks like this:

    <xpath expression='(//td)[3]/text()'>
          <get var="stats1" />
    </xpath>

If stats1 has no value, the following happens:

INFO - Exception caught with try processor: Error parsing XPath expression (XPath = [null])!
ERROR - Invalid variable name '_error'
org.webharvest.exception.VariableException: Invalid variable name '_error'
    at org.webharvest.runtime.variables.VariableName.<init>(VariableName.java:32)
    at org.webharvest.runtime.ScraperContext.setLocalVar(ScraperContext.java:109)
    at org.webharvest.runtime.processors.TryProcessor$1.call(TryProcessor.java:88)
at org.webharvest.runtime.processors.TryProcessor$1.call(TryProcessor.java:85)    
    [...]

This line in TryProcessor.java is triggering the exception:

                context.setLocalVar("_error", CommonUtil.createVariable(e));

"_error" is getting rejected as an invalid variable name because of this test in VariableName.java:

    if (StringUtils.isBlank(name)
            || !name.matches("^[a-zA-Z][a-zA-Z0-9]*?$")) {
        throw new VariableException(format("Invalid variable name ''{0}''",
                name));

I don't see "_error" getting used anywhere else in the code, so I commented it out. That eliminated the problem.