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

Don't fail seeing a backup refering to non-existent disk #20

Merged
merged 4 commits into from
Oct 13, 2023

Conversation

ydirson
Copy link
Collaborator

@ydirson ydirson commented Oct 4, 2023

This is the code submitted as xenserver#70 (formerly xenserver#67)

@ydirson ydirson requested review from stormi and benjamreis October 4, 2023 14:00
diskutil.py Outdated Show resolved Hide resolved
product.py Outdated Show resolved Hide resolved
@ydirson ydirson requested a review from stormi October 5, 2023 15:32
product.py Outdated
backup.version <= THIS_PLATFORM_VERSION:
if backup.version < XENSERVER_MIN_VERSION:
logger.log("findXenSourceBackups: ignoring, platform too old: %s < %s" %
(backup.version, XENSERVER_MIN_VERSION))
Copy link
Member

Choose a reason for hiding this comment

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

Should be indented like line 545?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At first I thought your remark was about the different indent wrt if of line 537.
This indeed made me focus on the role of these nested if's: as an extra condition for the whole nominal path, it makes a case for getting back to the lightweight try:except in my original refactor (idiom akin to goto fail error paths in C)

- it is bad practice to "catch any"
- not logging anything just hides information, which can be especially
  important here as the reason for a try/catch is not obvious (exceptions
  thrown by XenServerBackup.__init__?)

Signed-off-by: Yann Dirson <[email protected]>
Previous code structure was that of 2 nested if's, with nominal code
path being in the positive branch of each if.  Adding another
condition will bring a need for logging the reason to ignore a backup,
but doing that by converting inner `if` to an `elif` chain (arguably
the simplest modification) would bring the nominal code path to switch
to the negative/last branch of the inner `elif` chain.  At the same
time, the outer `if` would not seem special enough to deserve it
special place (and the cyclomatic complexity).

This commit leverages the existing `try:except:` block to switch to an
"error out the loop" pattern, where the nominal code path is just
linear.

Using `StopIteration` may feel like an abuse, but:
- it is the only standard `Exception` that is not a `StandardError` or
  a `Warning`, and defining a new one could seem overkill
- the closest alternative would be a `while True` loop and breaking out
  in both exceptional code paths and at the end of nominal path, where
  the `break` statements would "stop the iteration" as well

Signed-off-by: Yann Dirson <[email protected]>
@ydirson ydirson requested a review from stormi October 9, 2023 08:59
@ydirson ydirson changed the base branch from 10.10.8-8.3 to 10.10.9-8.3 October 13, 2023 14:13
@ydirson ydirson merged commit f03428b into 10.10.9-8.3 Oct 13, 2023
ydirson added a commit that referenced this pull request Dec 15, 2023
Don't fail seeing a backup refering to non-existent disk
ydirson added a commit that referenced this pull request Apr 18, 2024
Don't fail seeing a backup refering to non-existent disk
ydirson added a commit that referenced this pull request Apr 19, 2024
Don't fail seeing a backup refering to non-existent disk
ydirson added a commit that referenced this pull request Apr 19, 2024
Don't fail seeing a backup refering to non-existent disk
ydirson added a commit that referenced this pull request Apr 19, 2024
Don't fail seeing a backup refering to non-existent disk
ydirson added a commit that referenced this pull request Jul 2, 2024
Don't fail seeing a backup refering to non-existent disk
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.

3 participants