deepin-autotest-framework icon indicating copy to clipboard operation
deepin-autotest-framework copied to clipboard

return in finally swallows exceptions

Open iritkatriel opened this issue 1 year ago • 1 comments

In https://github.com/linuxdeepin/youqu/blob/master/src/depends/dogtail/tree.py#L324 there is a return statement in a finally block, which would swallow any in-flight exception.

This means that if an unhandled exception (including a BaseException such as KeyboardInterrupt) is raised from the try body, it will not propagate on as expected.

See also https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions.

iritkatriel avatar Oct 25 '24 20:10 iritkatriel

oh, yes

Maybe I can fix it like this:

class Node:
    ...
    
    def actions(self):
        actions = {}
        try:
            action = self.queryAction()
            for i in range(action.nActions):
                a = Action(self, action, i)
                actions[action.getName(i)] = a
        except Exception as e:
            print(f"An error occurred: {e}")
        return actions

mikigo avatar Oct 26 '24 05:10 mikigo