Don't fail seeing a backup refering to non-existent disk#70
Conversation
|
BTW... got the error too this morning. Pretty boring indeed. |
7a99335 to
44624db
Compare
| backups.append(backup) | ||
| except: | ||
| if not os.path.exists(os.path.join(b.mount_point, '.xen-backup-partition')): | ||
| raise StopIteration() |
There was a problem hiding this comment.
I found this raising StopIteration and catching it weird and hard to read. Why not using a try/finally doing the b.umount() in the finally and using continue here?
There was a problem hiding this comment.
The lack of break equivalent for try blocks is a problem. I guess return [] here would be suitable enough if we did not have a loop.
I'm quite unsure how to make that more readable.
There was a problem hiding this comment.
You are inside a for loop, why not using break and/or continue ? Also, you can put the b.unmount() inside a finally section.
44624db to
4897a5f
Compare
|
Rebased, and improved the exception logging in patch 2 |
4897a5f to
561a17b
Compare
|
Dropped the first commit, made unnecessary by #237 |
- 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 <yann.dirson@vates.fr>
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 <yann.dirson@vates.fr>
…rver#66) Signed-off-by: Yann Dirson <yann.dirson@vates.fr>
6cea3a1 to
7ef3e08
Compare
|
Rebased, no conflicts. Is there anything holding back this PR? |
This fixes the various problems seen as part of #66, and then some.
This is a continuation of #67 which got closed when
xs8was destroyed and cannot be reopened (thx github).