Platforms tested: Ignition 8.0.12 and 8.0.13.
I was using the asynchronous methods with the new http client provided in Ignition 8 via system.net.httpClient()
. The promise returned from the async methods has a whenComplete()
method. When I use a callback with whenComplete()
any errors/exceptions that occur in the callback are swallowed. I expected that errors would be recorded but instead they are never shown in the gateway log or wrapper log. There is no indication that an error occurred. It is as if code execution ceases at the point of the error.
Here is an example script:
client=system.net.httpClient()
promise=client.getAsync('https://httpbin.org/get')
def got_response(response, error):
logger=system.util.getLogger('temp')
logger.info('before the exception') # shows in the logs
raise Exception('error') # not shown in any logs
logger.info('after the exception') # never executed
promise.whenComplete(got_response)
I was extremely confused when some of my code in the callback never ran. Eventually I figured out that errors were being swallowed and had to use something like this:
from java.lang import Throwable
logger=system.util.getLogger('temp')
try:
#if I want to detect errors, I have to put my code in here
except BaseException as e:
logger.error('python exception: %s' % e)
except Throwable as e:
logger.error('java throwable: %s' % e)
In my case I had to match on Throwable in addition to Python’s BaseException since the error I was encountering was a Java Exception.
I’m assuming that the behavior of swallowing errors is a bug rather than being intended. Can someone at Inductive Automation open a bug for this?