Skip to content

Commit f70129b

Browse files
Avoid Division By Zero exception
If there are no elements in the result set, the TotalElement property is zero, which leads to an exception
1 parent 5696661 commit f70129b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

downloader/progress.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func progressLoop() {
3232
startTime := time.Now()
3333
bar.Format("╢▌▌░╟")
3434
for percentage < 100 {
35-
percentage = int((downloader.DoneElements * 100) / downloader.TotalElements)
35+
if (downloader.TotalElements > 0) {
36+
percentage = int((downloader.DoneElements * 100) / downloader.TotalElements)
37+
}
3638

3739
ETAuint64, _ := big.NewFloat(0).Quo(big.NewFloat(0).Quo(big.NewFloat(0).Sub(big.NewFloat(0).SetUint64(downloader.TotalElements), big.NewFloat(0).SetUint64(downloader.DoneElements)), big.NewFloat(1000)), big.NewFloat(averageTimePer1000)).Uint64()
3840
ETAtime := time.Duration(ETAuint64) * time.Millisecond * ETAFactor

0 commit comments

Comments
 (0)