Subject: Re: bug#49263: Guix weather backtrace

From: Maxime Devos <[email-masked]>
Date: Tue, 29 Jun 2021 00:12:27 +0200

Jack Hill schreef op ma 28-06-2021 om 16:15 [-0400]:
> computing 0 package derivations for aarch64-linux...
> [...]
> Throw to key `numerical-overflow' with args `("/" "Numerical overflow" #f #f)'.

A division by zero problem?
Also, this seems architecture-dependent:

$ guix weather icecat --system=x86_64-linux icecat

2 pakketdistillaties aan het berekenen voor x86_64-linux...
op zoek naar 2 depotobjecten op https://ci.guix.gnu.org...
https://ci.guix.gnu.org
  100.0% substituten beschikbaar (2 van de 2)
  ten minste 355,2 MiB aan narbestanden (gecomprimeerd)
  377,9 MiB op schijf (ongecomprimeerd)
  0,379 seconden per verzoek (0,8 seconden in totaal)
  2,6 verzoeken per seconde

$ guix weather icecat --system=aarch64-linux icecat

0 pakketdistillaties aan het berekenen voor aarch64-linux...
op zoek naar 0 depotobjecten op https://ci.guix.gnu.org...
https://ci.guix.gnu.org
Backtrace: [...]
Throw to key `numerical-overflow' with args `("/" "Numerical overflow" #f #f)'.

Seems like the definition of icecat or some dependency of icecat does
not support aarch64. Anyway, here is a patch. Could you confirm it works?

Greetings,
Maxime.
From 1d87e33360c9897a77b7e172f16e3cd1973c959d Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Tue, 29 Jun 2021 00:06:34 +0200
Subject: [PATCH] weather: Handle zero requested store items gracefully.

This can happen if the weather information of a package
is requested for an unsupported system.  For example,
try "guix weather icecat --system=aarch64-linux".

* guix/scripts/weather.scm
  (report-server-coverage): Do not divide by zero when zero
  store items are requested from a server.

Fixes: <https://issues.guix.gnu.org/49263>
Reported-By: Jack Hill <[email-masked]>
---
 guix/scripts/weather.scm | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/guix/scripts/weather.scm b/guix/scripts/weather.scm
index 6d925d416c..06312d65a2 100644
--- a/guix/scripts/weather.scm
+++ b/guix/scripts/weather.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2017 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2018 Kyle Meyer <[email-masked]>
 ;;; Copyright © 2020 Simon Tournier <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -185,9 +186,12 @@ or #f if it could not be determined."
                                  #:key display-missing?)
   "Report the subset of ITEMS available as substitutes on SERVER.
 When DISPLAY-MISSING? is true, display the list of missing substitutes.
-Return the coverage ratio, an exact number between 0 and 1."
+Return the coverage ratio, an exact number between 0 and 1.
+In case ITEMS is an empty list, return 1 instead."
   (define MiB (* (expt 2 20) 1.))
 
+  ;; TRANSLATORS: it is quite possible zero store items are
+  ;; looked for.
   (format #t (G_ "looking for ~h store items on ~a...~%")
           (length items) server)
 
@@ -208,9 +212,10 @@ Return the coverage ratio, an exact number between 0 and 1."
                                  narinfos))
           (time      (+ (time-second time)
                         (/ (time-nanosecond time) 1e9))))
-      (format #t (G_ "  ~,1f% substitutes available (~h out of ~h)~%")
-              (* 100. (/ obtained requested 1.))
-              obtained requested)
+      (when (> requested 0)
+        (format #t (G_ "  ~,1f% substitutes available (~h out of ~h)~%")
+                (* 100. (/ obtained requested 1.))
+                obtained requested))
       (let ((total (/ (reduce + 0 sizes) MiB)))
         (match (length sizes)
           ((? zero?)
@@ -299,7 +304,9 @@ are queued~%")
 
       ;; Return the coverage ratio.
       (let ((total (length items)))
-        (/ (- total (length missing)) total)))))
+        (if (> total 0)
+            (/ (- total (length missing)) total)
+            1)))))
 
 
 ;;;
-- 
2.32.0