Runscript expression error

Hi,
I have a script in the shared library which can be called using script console no problem but not from expression.
Is there any reasoning for this. Please see below.

Is there an error in the console or anything useful in the diagnostics?

Maybe that reference to datetime isn’t working without an import?

It has the import at the top.
The function works when called from the script console.Just not when it’s called from an expression.
Only error is - "Error executing runScript()

Consider wrapping your script in a try-except block and logging the errors encountered.

Is there a way to show the error using a try in expression?

No, the entire point of the try expression function is that it silently wraps errors.

The quickest thing to do is make a new function that calls the original function from a try-except block…

import java.lang.Exception
logger = system.util.getLogger("someLogger")

def Energy_calc_trapped(TagName, timeframe):
    try:
        return Energy_calc(TagName, timeframe)
    except java.lang.Exception, e):
        logger.warn("Unable to compute Energy", e)
    except Exception, e:
        logger.warnf("Unable to compute Energy: %s", e)
    return 0

Consider using the class PythonAsJavaException from later.py if you need more detail of the python exception case.

Answer was in the tag name.
When called from the expression it needed [default] at the front