-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
Signed-off-by: Yann Dirson <[email protected]>
5d6d617
to
6a9b16c
Compare
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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
6a9b16c
to
9771df0
Compare
- 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]>
…rver#66) Signed-off-by: Yann Dirson <[email protected]>
9771df0
to
7a99335
Compare
Don't fail seeing a backup refering to non-existent disk
Don't fail seeing a backup refering to non-existent disk
Don't fail seeing a backup refering to non-existent disk
Don't fail seeing a backup refering to non-existent disk
Don't fail seeing a backup refering to non-existent disk
Don't fail seeing a backup refering to non-existent disk
This is the code submitted as xenserver#70 (formerly xenserver#67)