# Tags with Script Failures

**URL:** <https://forum.inductiveautomation.com/t/tags-with-script-failures/38212>\
**Category:** Ignition\
**Created:** [August 31, 2020, 3:28pm UTC](https://forum.inductiveautomation.com/t/tags-with-script-failures/38212 "2020-08-31T15:28:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CJVR](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CJVR](https://forum.inductiveautomation.com/u/CJVR)\
**Post date:** [August 31, 2020, 3:28pm UTC](https://forum.inductiveautomation.com/t/tags-with-script-failures/38212/1 "2020-08-31T15:28:09Z")

</div>

Occasionally (more than I care to admit!) I have tags that will have a script “crash” (usually onChange scripts). I only find out about them when something goes wrong someplace else. Is there a way to query the tag database to see if there tags with script errors? Even better, is there a way to somehow notify me when there is a script error?

The wrapper file USUALLY has the error (sometimes it does not). I could write something that periodically checks the file for script errors but I was hoping for an easier and more elegant solution.

Thanks

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 31, 2020, 3:34pm UTC](https://forum.inductiveautomation.com/t/tags-with-script-failures/38212/2 "2020-08-31T15:34:30Z")

</div>

Put your script in a try except block, then log the error to a database or another tag or something like that.

```auto
try:
    my script
except:
    system.tag.write('error',"xTag script failed")
```

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [August 31, 2020, 3:52pm UTC](https://forum.inductiveautomation.com/t/tags-with-script-failures/38212/3 "2020-08-31T15:52:05Z")

</div>

I would do something like:

```auto
	import traceback
	import sys
	
	try:
		your script here
	except Exception, err:
		exc_type, exc_value, exc_tb = sys.exc_info()
		errtb = traceback.format_exception(exc_type, exc_value, exc_tb)
		errStr = "Tag Path: "+str(tagPath)+" Tag Script Error: "+str(err)+errtb[1] + errtb[2]
		logger = system.util.getLogger("Tag test")
		logger.info(errStr)

```

Its similar to what @dkhayes117 suggested but instead of using a tag on fail, it will use the gateway log and will tell you a little about the error including the line it comes from.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/5/65b7c7c4aa0220f0faff120fb525ddd5461f86c2.png)

---

<div class="post-metadata">

**Author:** ![CJVR](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CJVR](https://forum.inductiveautomation.com/u/CJVR)\
**Post date:** [September 2, 2020, 2:34pm UTC](https://forum.inductiveautomation.com/t/tags-with-script-failures/38212/4 "2020-09-02T14:34:07Z")

</div>

Thanks. I used a modified version of @bpreston 's script and that will be helpful. It would be nice, though, to quickly find tags in error for any reason (evaluation, event script, etc.).
