# Runscript expression error

**URL:** <https://forum.inductiveautomation.com/t/runscript-expression-error/24512>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [April 30, 2019, 3:01pm UTC](https://forum.inductiveautomation.com/t/runscript-expression-error/24512 "2019-04-30T15:01:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![oisin.gribben](https://avatars.discourse-cdn.com/v4/letter/o/9d8465/32.png) [@oisin.gribben](https://forum.inductiveautomation.com/u/oisin.gribben)\
**Post date:** [April 30, 2019, 3:01pm UTC](https://forum.inductiveautomation.com/t/runscript-expression-error/24512/1 "2019-04-30T15:01:55Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8973c1b812f5532ca73e258f24fb64d45cd2afee.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/de10c4a5bac62c97e9a1a78e23819cb97e8a3eb5.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 30, 2019, 3:05pm UTC](https://forum.inductiveautomation.com/t/runscript-expression-error/24512/2 "2019-04-30T15:05:47Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![oisin.gribben](https://avatars.discourse-cdn.com/v4/letter/o/9d8465/32.png) [@oisin.gribben](https://forum.inductiveautomation.com/u/oisin.gribben)\
**Post date:** [April 30, 2019, 3:10pm UTC](https://forum.inductiveautomation.com/t/runscript-expression-error/24512/3 "2019-04-30T15:10:51Z")

</div>

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()

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 30, 2019, 3:11pm UTC](https://forum.inductiveautomation.com/t/runscript-expression-error/24512/4 "2019-04-30T15:11:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oisin.gribben](https://avatars.discourse-cdn.com/v4/letter/o/9d8465/32.png) [@oisin.gribben](https://forum.inductiveautomation.com/u/oisin.gribben)\
**Post date:** [April 30, 2019, 3:23pm UTC](https://forum.inductiveautomation.com/t/runscript-expression-error/24512/5 "2019-04-30T15:23:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 30, 2019, 4:18pm UTC](https://forum.inductiveautomation.com/t/runscript-expression-error/24512/6 "2019-04-30T16:18:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 30, 2019, 4:47pm UTC](https://forum.inductiveautomation.com/t/runscript-expression-error/24512/7 "2019-04-30T16:47:40Z")

</div>

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

```auto
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](https://www.automation-pros.com/ignition/later.py) if you need more detail of the python exception case.

---

<div class="post-metadata">

**Author:** ![oisin.gribben](https://avatars.discourse-cdn.com/v4/letter/o/9d8465/32.png) [@oisin.gribben](https://forum.inductiveautomation.com/u/oisin.gribben)\
**Post date:** [May 1, 2019, 8:20am UTC](https://forum.inductiveautomation.com/t/runscript-expression-error/24512/8 "2019-05-01T08:20:36Z")

</div>

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