Perspective pass exception to view

Ignition 8.0.16

I’m not totally sure if I’m doing this the correct way however here we go.

I’ve got a footer dock that I’m using to signal to the user when an exception occurs. I open that dock in a try/except block. Basically I’m showing a small information about the error, and then I have a link on that dock to pass the exception to another view that would display the entire exception stack trace. This is all wrapped up in a script to handle this.

def showErrorDock(message,exception):
	import system.perspective
	dockId = 'dockFooterError'
	system.perspective.openDock(
		id = dockId,
		params = {
			'dockId':dockId,
			'message':message,
			'exception':exception
		}
	)

I’m calling this in a test like this:

	try:
		i = 1/0
	except Exception, e:
		docks.showErrorDock(message = 'Testing Error Dock',exception = e)

I’m getting an error in the gateway:

Error running action 'dom.onClick' on Pages/Home@C/root/FlexContainer/FlexContainer_0/Label_2: Traceback (most recent call last): File "<function:runAction>", line 5, in runAction File "<module:docks>", line 4, in showErrorDock TypeError: object of type 'exceptions.ZeroDivisionError' has no len()

So I think this is happening when the data is passed out to the error page view. Any ideas on how to make this happen? Do I need to wrap the exception in another data-type to effectively pass it along?

Short answer:

def showErrorDock(message,exception):
	import system.perspective
	dockId = 'dockFooterError'
	system.perspective.openDock(
		id = dockId,
		params = {
			'dockId':dockId,
			'message':message,
			'exception':str(exception)
		}
	)

Long answer:
What’s happening is that the params are being parsed as JSON types (strings, numbers, booleans, lists, dictionaries), but you’re passing an Exception Object, which the View is not prepared to accept. Aside from JSON types there are only two valid value types that you can use as values within Perspective: dates and DataSets. If you wrap the exception object as a str at some point before it’s sent as a Perspective value, then your code will work.

When sending Perspective a value, that value’s type should always be from the following list: str, bool, int (float, double, etc), list, dict, DataSet, or Date (most likely unix timestamp, ie: 1603806000).

1 Like