Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Throw Exception on Warning messages - Python API

#1
IS:
When using Item.SetParent to set an item to be a child of one of its own children, a TimeoutError occurs.

REQUESTED CHANGE:
When using Item.SetParent to set an item to be a child of one of its own children, a descriptive exception is thrown. (I would suggest something like a "GenealogyError".)

Example:


Code:
RDK = robolink.Robolink()
item_a = RDK.AddFrame('item_a')
item_b = RDK.AddFrame('item_b', itemparent=item_a)
item_c = RDK.AddFrame('item_c', itemparent=item_b)
try:
    item_a.setParent(item_b)
except robolink.GenealogyError as e:
    print(e)
>> CannotSetItemToChildOfItsOwnDescendant
try:
    item_a.setParentStatic(item_b)
except robolink.GenealogyError as e:
    print(e)
>> CannotSetItemToChildOfItsOwnDescendant
try:
    item_a.setParent(item_c)
except robolink.GenealogyError as e:
    print(e)
>> CannotSetItemToChildOfItsOwnDescendant
#2
You should not see a timeout error. Did you try with the latest version of RoboDK? The function should run through without taking any action. You should see this warning message though:
Code:
WARNING: The parent can not be a child of the current item
On the other hand, we could modify the API to throw an exception when Warnings are displayed. This can be done manually (for example, editing status 2 inside the function _check_status). 

We'll also add a configuration flag to enable throwing exceptions when a warning occurs.
#3
That's weird -- looks like I can't reproduce this issue in an isolated workstation, even a large one with many more frames than the example code I provided. In that case, I am not sure why I was seeing this issue yesterday, but it went away when I fixed the parent/child issue. I'll mark this resolved and reopen if I can reproduce the issue I was seeing.

I like the configuration flag for exceptions, that would be great. Thanks!
#4
This update is ready for the Python API (on the official RoboDK API GitHub). You can now set the _RAISE_EXCEPTION_ON_WARNING variable to True to raise exceptions when a warning is provided by RoboDK.

Example:
Code:
RDK = Robolink()
RDK._RAISE_EXCEPTION_ON_WARNING = True
...
#5
Thanks, Albert!
  




Users browsing this thread:
1 Guest(s)