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 #67

Closed
wants to merge 4 commits into from

Conversation

ydirson
Copy link
Contributor

@ydirson ydirson commented Oct 4, 2023

This fixes the various problems seen as part of #66, and then some.

@ydirson ydirson marked this pull request as draft October 4, 2023 10:36
@ydirson ydirson changed the base branch from master to xs8 October 4, 2023 13:43
@ydirson ydirson marked this pull request as ready for review October 4, 2023 13:52
@ydirson ydirson force-pushed the inexistant-disks branch 2 times, most recently from 6a9b16c to 9771df0 Compare October 6, 2023 13:30
- 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]>
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