Gateway Messages and Exceptions

First things first.
Ignition version is 8.1.1

When a remote gateway messageHandler is called and an exception is generated, it seems that the handling between a python exception and a java exception is different. It maybe my lack of understanding though between the two.

If I have a two different messageHandlers in a remote gateway like so:

pythonException

return ValueError('This is an uncaught python exception')

and

javaException

import java.lang.Exception
raise java.lang.Exception('This is an uncaught java exception')

Then I call the pythonException as follows:

def onSuccess(message):
	inProgress = False
	if not inProgress:
		inProgress = True
		print 'onSuccess'
		print message
		print type(message)

def onError(message):
	inProgress = False
	if not inProgress:
		inProgress = True
		print 'onError'
		print message
	

reqObj = system.util.sendRequestAsync(
	project='TicketTrackSync',
	messageHandler='pythonException',
	remoteServer='ignition-esp_hcp_whi'
)
reqObj.onSuccess(onSuccess)
reqObj.onError(onError)

I end up getting the onSuccess call back:

>>> onSuccess
This is an uncaught python exception
<type 'exceptions.ValueError'>

However if I call the javaException as follows:

def onSuccess(message):
	inProgress = False
	if not inProgress:
		inProgress = True
		print 'onSuccess'
		print message
		print type(message)

def onError(message):
	inProgress = False
	if not inProgress:
		inProgress = True
		print 'onError'
		print message
	

reqObj = system.util.sendRequestAsync(
	project='TicketTrackSync',
	messageHandler='javaException',
	remoteServer='ignition-esp_hcp_whi'
)
reqObj.onSuccess(onSuccess)
reqObj.onError(onError)

I end up getting the onError call back:

>>> onError
java.lang.Exception: Gateway-side exception: java.lang.Exception: Remote exception: Traceback (most recent call last):
  File "<MessageHandlerScript:TicketTrackSync/javaException >", line 12, in handleMessage
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

	at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)

	at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:211)

java.lang.Exception: java.lang.Exception: This is an uncaught java exception

Is this by design? I’m sending data across to a remote gateway that MAY have issues with a database insert, and I want to make 100% sure that I can capture and report errors that occur. Right now I’m doubling up on the onSuccess and onError call back with checks on the message to make sure that I don’t miss an exception, but it feels like a python exception should also generate the onError rather than just the java one.

You are not raising a Python Exception here but your function simply returns a result of type ValueError . Use raise ValueError... like you do with the java Exception.

DOH. I knew I missed something in my validation testing.

Thanks for pointing that out.

When I changed it to raise it is working as I expected