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

Fix division by zero #159

Merged
merged 1 commit into from
Aug 2, 2017
Merged

Conversation

sqozz
Copy link
Contributor

@sqozz sqozz commented May 10, 2017

reads can be zero sometimes an will then cause a ZeroDivisionError in the changed line.
This can happen after calling:
$ whipper offset find

@JoeLametta JoeLametta changed the title Fix devision by zero Fix division by zero May 21, 2017
@@ -196,7 +196,7 @@ def getTrackQuality(self):

# don't go over a 100%; we know cdparanoia reads each frame at least
# twice
return min(frames * 2.0 / reads, 1.0)
return min(frames * 2.0 / reads, 1.0) if reads else 0
Copy link
Member

@Freso Freso Jun 1, 2017

Choose a reason for hiding this comment

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

This doesn't seem very Pythonic to me. Something like

if reads:
    return min(…)
else:
    return 0

looks better to me. Or maybe even just assigning to a variable:

quality = 0
if reads:
    quality = min(frames * 2.0 / reads, 1.0)
return quality

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I thought about this and wanted to preserve this beauty of code with only one return path (and the min()). If you ask me the most pythonic is to ask for forgiveness and not permission. So what about a try-expect block that catches the division by zero exception?

Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW, I haven't checked: is it OK to have reads with a value of 0? (is there any underlying bug?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most likely my CD drive was somewhat broken because I didn't even managed to rip one single CD with it but regardless of that; whipper should catch it IMHO.
In the long run one could think about throwing actual error messages if the drive operates weird (like here).

Copy link
Collaborator

Choose a reason for hiding this comment

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

If that's the reason, I think it's better to rely on the try ... except solution for that's more expressive in this case (unexpected error).

Copy link
Collaborator

@JoeLametta JoeLametta left a comment

Choose a reason for hiding this comment

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

Please rewrite it using a try ... except

@bb010g
Copy link

bb010g commented Aug 2, 2017

Can this be merged now?

@sqozz
Copy link
Contributor Author

sqozz commented Aug 2, 2017

At least nothing to add from my side

@JoeLametta JoeLametta merged commit 3f248bf into whipper-team:master Aug 2, 2017
@JoeLametta
Copy link
Collaborator

At least nothing to add from my side

Merged, thanks.

@RecursiveForest
Copy link
Contributor

I would actually request this be un-merged and reviewed for why there's a division by zero happening before we decide to just eat the error.

@sqozz
Copy link
Contributor Author

sqozz commented Aug 5, 2017

@RecursiveForest this is just a fix for a progress indicator which caused whipper to fully crash. It does not influence the rips…
But to answer your question: A division by zero happens here because cdparanoia returns 0 bytes as result which happened most likely because of a faulty CD drive.

JoeLametta added a commit that referenced this pull request Nov 9, 2018
This commit effectively reverts #159. Whipper now raises an exception again but with a clearer textual description.

Closes #202.
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.

5 participants