Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XenAPIPlugin.py: Remove the superflous catch & raise of SystemExit #5803

Conversation

ashwin9390
Copy link
Contributor

@ashwin9390 ashwin9390 commented Jul 10, 2024

When reviewing XAPIPlugin.py for warning fixes,

Bernhard found a superfluous catch and raise in XenAPIPlugin.py's dispatch() function
that we can clean up:

Commmit message:

SystemExit does not need to be caught and raised in this try:
Both other exceptions are subclasses of Exception, so they don't catch SystemExit(BaseException):

By design, SystemExit is a subclass of BaseException and because we are not catching BaseException and also not use a bare except: here, we can cleanup catching and re-raising SystemExit() here.
Reference: https://docs.python.org/3/library/exceptions.html#SystemExit

Author / Signed-off-by: Bernhard Kaindl bernhard.kaindl@cloud.com

Committed by: Signed-off-by: Ashwinh ashwin.h@cloud.com

In `XenAPIPlugin.py`'s `dispatch()` function, SystemExit does not need to be
caught and raised because both other exceptions are subclasses of Exception:

By design, SystemExit is a subclass of BaseException and because we
are not catching BaseException and also not use a bare `except:`
here, we can cleanup catching and re-raising `SystemExit()` here.

Reference: https://docs.python.org/3/library/exceptions.html#SystemExit

Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
Copy link
Collaborator

@bernhardkaindl bernhardkaindl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening and reviewing this PR. I wanted to add the reference:

https://docs.python.org/3/library/exceptions.html#SystemExit

Quote:

exception SystemExit
This exception is raised by the sys.exit() function.
It inherits from BaseException instead of Exception so that it is not accidentally caught by code that catches Exception.
This allows the exception to properly propagate up and cause the interpreter to exit.

Hence, as we are not catching BaseException (Failure is also a subclass of Exception) in this try (and we also are not using a bare except:, the SystemExit BaseException will traverse this try without getting chatched. Thus, catching and re-raising it is not needed.

@psafont psafont merged commit 3786289 into xapi-project:feature/py3 Jul 10, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants