I'm noticing a problem with user defined exceptions depending on designer vs gateway scope.
This is the production code in question:
if is_property_name_thing_one(property_name):
logger.infof("its a thing one")
try:
logger.infof("trying to get it")
...
except Shared.exceptions.LotNotFoundException:
logger.infof("going to import thing one")
...
except Exception as e:
logger.errorf(traceback.format_exc())
logger.errorf("e type: [%s]" % type(e))
raise e
I'm trying to write tests that exercises this code. When I run the test code via a perspective button press, I get the following in the logs:
run_random_work_order_test 24Sep2024 08:15:39 its a thing one
run_random_work_order_test 24Sep2024 08:15:39 trying to get it
run_random_work_order_test 24Sep2024 08:15:39 going to import thing one
When I run the test code via the script console, I get the following in the logs:
08:16:14.320 [SwingWorker-pool-1-thread-10] INFO run_random_work_order_test - its a thing one
08:16:14.321 [SwingWorker-pool-1-thread-10] INFO run_random_work_order_test - trying to get it
08:16:14.382 [SwingWorker-pool-1-thread-10] ERROR run_random_work_order_test - Traceback [the-trace-back]
08:16:14.383 [SwingWorker-pool-1-thread-10] ERROR run_random_work_order_test - e type: [<class 'exceptions.LotNotFoundException'>]
I've consistently seen this behavior when doing testing via the script console and in my tests have started to get the string of the error type and doing a string comparison in my tests, but I'm unwilling to alter production code to get around this problem. Any help or info would be greatly appreciated. Thanks.
The designer script console is not compatible with Perspective scope for anything but trivial code. Use a button action or similar to test from within Perspective.
The script console runs in Designer Scope, which is a variant of Vision Client scope, which I hope you can see is completely different from Perspective.
Perspective runs in a Gateway Scope, everything you do in perspective is run on the gateway. For some things which are not specific to a particular Ignition Scoping, the script console is great for testing. But when it comes to things that are specific to any scope other than Vision Client scope (and really even that has some restrictions), its just not compatible. It can lead you astray making you think that the code you've developed works, but then in application it doesn't work because for instance functions are expecting a different signature. There are various other gotchas as well.
Use a Gateway Message Handler, button action, or other type of perspective scripting to force the code execution into the correct scope.
When looking in the manual, pay attention to what scopes a function is available in, this will let you know what signature should be used or if the function is even available to perspective.