Way to allow Send Report for custom errors?

I’ve been refactoring my project heavily with a large addition being error try/catching.

I previously had set up the Igntition error reports to be sent to me so when someone sees the red box of death they can email me the error stack.

Is there a way to do that with my custom errors? Some way to enable system.gui functons to be able to send reports to the same address listed on the gateway?

You can import ErrorUtil and call showError; eg:

from com.inductiveautomation.ignition.client.util.gui import ErrorUtil
try:
    <some python code>
except ValueError as e:
    ErrorUtil.showError("Something went wrong", e)
1 Like

Hm almost. I did this to cause an error in a button on click extenstion.

from com.inductiveautomation.ignition.client.util.gui import ErrorUtil
try:
	len(something)
except Exception, e:
	ErrorUtil.showError("Some Error happened", str(e))

And I get this
image
But I can’t click details and therefore cannot send report.

By using the (String, String) overload instead of the (String, Throwable) overload, you put the error info into the title.

Try the version Paul suggested, without stringifying the error.

Ok that got me closer but only becuase it seems to actually be causing an error within ErrorUtil.

My current code

from com.inductiveautomation.ignition.client.util.gui import ErrorUtil
try:
    len(nonExistantVariable)
except Exception as e:
    ErrorUtil.showError("Something went wrong", e)


Think I had to do this -

from com.inductiveautomation.ignition.client.util.gui import ErrorUtil
import java.lang.Exception
try:
    len(nonExistantVariable)
except java.lang.Exception as e:
    ErrorUtil.showError("Something went wrong", e)a

But then I don’t see that “Something went wrong” error message anywhere.
image
image

You need to coerce the Python exception back into a Java exception to pass it into ErrorUtil. Something like this:

import java.lang.Exception
from org.python.core import Py, PyObject
from com.inductiveautomation.ignition.client.util.gui import ErrorUtil

try:
    len(nonExistantVariable)
except (java.lang.Exception, Exception) as e:
	if (isinstance(e, PyObject)):
		e = Py.makeException(pye)
	ErrorUtil.showError("Something else went wrong", e)

For bonus usage points, since Ignition 8 is using Jython 2.7, you can use a context manager:

class ErrorHandler:
	def __init__(self, message = "Something went wrong"):
		self.message = message
		
	def __enter__(self):
		return self
		
	def __exit__(self, exc_type, exc_value, traceback):
		if (isinstance(exc_type, PyObject)):
			exc_value = Py.makeException(exc_value)
		ErrorUtil.showError(self.message, exc_value)

In use:

with ErrorHandler("Unexpected Error"):
	len(nonexistent)

So you don’t have to write your try/catch and import statements each time - you can just have your context manager defined in a project library.