Igalia / acacia

Library for inspecting accessibility APIs
https://igalia.github.io/acacia
GNU Lesser General Public License v2.1
8 stars 1 forks source link

Catch and don't throw from "toString" methods for IA2 and Atspi #213

Open spectranaut opened 7 months ago

spectranaut commented 7 months ago

Joanie mentioned wanting to print all the data we could get on a tree, and not stopping if something returns an error.

Maybe the "toString" can print information, and not throw, to be used for this purpose.

spectranaut commented 7 months ago

For example, when getting some node data on some nodes in libreoffice, we are getting error codes from the IA2 API.

For example, IAAction::toString throws on a menu item:

------> ROLE_SYSTEM_MENUITEM Name='File', Description='',  States=('FOCUSABLE', 'HASPOPUP', 'OPAQUE')
...
  File "C:\Users\spectranaut\repos\AXAccess\build\bin\dump_tree_ia2.py", line 28, in print_tree
    print("  " * level + "* " + action.toString())
                                ^^^^^^^^^^^^^^^^^
  File "C:\Users\spectranaut\repos\AXAccess\build\bin\acacia_ia2.py", line 314, in toString
    return _acacia_ia2_python.IAAction_toString(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: ERROR: get_name failed: E_NOTIMPL

And this failure:

--> IA2_ROLE_ROOT_PANE ROLE_SYSTEM_CLIENT Name='Untitled 1 — LibreOffice Writer', Description='',  States=('FOCUSABLE',)
...
  File "C:\Users\spectranaut\repos\AXAccess\build\bin\dump_tree_ia2.py", line 22, in print_tree
    properties = ia2.toString()
                 ^^^^^^^^^^^^^^
  File "C:\Users\spectranaut\repos\AXAccess\build\bin\acacia_ia2.py", line 280, in toString
    return _acacia_ia2_python.IA2_toString(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: ERROR: get_attributes failed: E_FAIL
spectranaut commented 6 months ago

When we encounter an error, we should print it in the string, for example, name=<error>

spectranaut commented 6 months ago

It turns out it is very difficult to get Atspi to return an error message, error messages are only returned in special cases. We do get a lot of warnings thrown out to the terminal from these kinds of checks in the Atspi code instead: https://docs.gtk.org/glib/warnings.html

Other places it throws errors (like Orca inspects to see if an object is dead) will usually happening when processing an event queue for objects that no longer exist, which will happen less often in a testing library.

However, I think we do need to do this change in IA2, as it clearly returns errors more often.