GNU bug report logs - #45983
[PATCH 0/3] Fix non-recursive importers gnu and json

Previous Next

Package: guix-patches;

Reported by: zimoun <zimon.toutoune <at> gmail.com>

Date: Tue, 19 Jan 2021 15:26:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45983 in the body.
You can then email your comments to 45983 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#45983; Package guix-patches. (Tue, 19 Jan 2021 15:26:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to zimoun <zimon.toutoune <at> gmail.com>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Tue, 19 Jan 2021 15:26:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: guix-patches <at> gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 0/3] Fix non-recursive importers gnu and json
Date: Tue, 19 Jan 2021 16:25:18 +0100
Dear,

The first patch is cosmetic.  Even, the file guix/import/gnu.scm should not
contain UI messages, IMHO.  Another story.

The two other patches fix the ugly backtrace throw by:

    guix import gnu do-not-exist
    guix import json do-no-exist

with something like:

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix import gnu do-not-exist
guix import: error: failed to determine latest release of GNU do-not-exist

$ ./pre-inst-env guix import json do-not-exist
guix import: error: invalid file name
--8<---------------cut here---------------end--------------->8---

See bug#44115 <http://issues.guix.gnu.org/44115#3> for details about the bug.

All the best,
simon


zimoun (3):
  import: gnu: Add internationalized messages.
  guix: gnu-maintenance: Fix error handling.
  scripts: import: json: Fix error handling.

 guix/gnu-maintenance.scm     |  5 ++++-
 guix/import/gnu.scm          | 11 +++++++++--
 guix/scripts/import/json.scm |  7 +++++--
 3 files changed, 18 insertions(+), 5 deletions(-)


base-commit: 2d9c6542c804eb2ef3d8934e1e3ab8b24e9bbafb
-- 
2.29.2





Information forwarded to guix-patches <at> gnu.org:
bug#45983; Package guix-patches. (Tue, 19 Jan 2021 15:28:02 GMT) Full text and rfc822 format available.

Message #8 received at 45983 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: 45983 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 1/3] import: gnu: Add internationalized messages.
Date: Tue, 19 Jan 2021 16:27:35 +0100
* guix/import/gnu.scm (gnu->guix-package): Add 'G_' to messages.
---
 guix/import/gnu.scm | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/guix/import/gnu.scm b/guix/import/gnu.scm
index 29324d7554..fe7a2f1e54 100644
--- a/guix/import/gnu.scm
+++ b/guix/import/gnu.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -19,6 +20,7 @@
 (define-module (guix import gnu)
   #:use-module (guix gnu-maintenance)
   #:use-module (guix import utils)
+  #:use-module (guix i18n)
   #:use-module (guix utils)
   #:use-module (guix store)
   #:use-module (gcrypt hash)
@@ -115,13 +117,18 @@ details.)"
          (#f
           (raise (condition
                   (&message
-                   (message "couldn't find meta-data for GNU package")))))
+                   (message
+                    (format #f
+                            (G_ "couldn't find meta-data for GNU ~a")
+                            name))))))
          (info
           (gnu-package->sexp info release #:key-download key-download)))))
     (_
      (raise (condition
              (&message
               (message
-               "failed to determine latest release of GNU package")))))))
+               (format #f
+                       (G_ "failed to determine latest release of GNU ~a")
+                       name))))))))
 
 ;;; gnu.scm ends here
-- 
2.29.2





Information forwarded to guix-patches <at> gnu.org:
bug#45983; Package guix-patches. (Tue, 19 Jan 2021 15:28:02 GMT) Full text and rfc822 format available.

Message #11 received at 45983 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: 45983 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 2/3] guix: gnu-maintenance: Fix error handling.
Date: Tue, 19 Jan 2021 16:27:36 +0100
Fixes partially <https://bugs.gnu.org/44115>.

* guix/gnu-maintenance.scm (latest-release): Handle 'ftp-error'.
---
 guix/gnu-maintenance.scm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/guix/gnu-maintenance.scm b/guix/gnu-maintenance.scm
index 08b2bcf758..0da6fc19b6 100644
--- a/guix/gnu-maintenance.scm
+++ b/guix/gnu-maintenance.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2012, 2013 Nikita Karetnikov <nikita <at> karetnikov.org>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -361,7 +362,9 @@ return the corresponding signature URL, or #f it signatures are unavailable."
 
   (let loop ((directory directory)
              (result    #f))
-    (let* ((entries (ftp-list conn directory))
+    (let* ((entries (catch 'ftp-error
+                      (lambda _ (ftp-list conn directory))
+                      (const '())))
 
            ;; Filter out things like /gnupg/patches.  Filter out "w32"
            ;; directories as found on ftp.gnutls.org.
-- 
2.29.2





Information forwarded to guix-patches <at> gnu.org:
bug#45983; Package guix-patches. (Tue, 19 Jan 2021 15:28:02 GMT) Full text and rfc822 format available.

Message #14 received at 45983 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: 45983 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 3/3] scripts: import: json: Fix error handling.
Date: Tue, 19 Jan 2021 16:27:37 +0100
Fixes partially <https://bugs.gnu.org/44115>.

* guix/scripts/import/json.scm (guix-import-json): Handle error.
---
 guix/scripts/import/json.scm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/guix/scripts/import/json.scm b/guix/scripts/import/json.scm
index 778e5f4bc5..63fba260ae 100644
--- a/guix/scripts/import/json.scm
+++ b/guix/scripts/import/json.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2014 Eric Bavier <bavier <at> member.fsf.org>
 ;;; Copyright © 2015, 2017 Ricardo Wurmus <rekado <at> elephly.net>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -88,8 +89,10 @@ Import and convert the JSON package definition in PACKAGE-FILE.\n"))
                            (reverse opts))))
     (match args
       ((file-name)
-       (or (json->code file-name)
-           (leave (G_ "invalid JSON in file '~a'~%") file-name)))
+       (if (file-exists? file-name)
+         (or (json->code file-name)
+             (leave (G_ "invalid JSON in file '~a'~%") file-name))
+         (leave (G_ "invalid file name~%"))))
       (()
        (leave (G_ "too few arguments~%")))
       ((many ...)
-- 
2.29.2





Information forwarded to guix-patches <at> gnu.org:
bug#45983; Package guix-patches. (Tue, 26 Jan 2021 22:16:02 GMT) Full text and rfc822 format available.

Message #17 received at 45983 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: zimoun <zimon.toutoune <at> gmail.com>
Cc: 45983 <at> debbugs.gnu.org
Subject: Re: bug#45983: [PATCH 0/3] Fix non-recursive importers gnu and json
Date: Tue, 26 Jan 2021 23:14:52 +0100
Hi,

zimoun <zimon.toutoune <at> gmail.com> skribis:

> * guix/import/gnu.scm (gnu->guix-package): Add 'G_' to messages.

[...]

> -                   (message "couldn't find meta-data for GNU package")))))
> +                   (message
> +                    (format #f
> +                            (G_ "couldn't find meta-data for GNU ~a")
> +                            name))))))
>           (info
>            (gnu-package->sexp info release #:key-download key-download)))))
>      (_
>       (raise (condition
>               (&message
>                (message
> -               "failed to determine latest release of GNU package")))))))
> +               (format #f
> +                       (G_ "failed to determine latest release of GNU ~a")

Please use ‘formatted-message’ instead.

Note that (message "foo") is subject to translation just like (G_
"foo").  See the ‘--keyword’ options in po/guix/Makevars.

Thanks,
Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#45983; Package guix-patches. (Tue, 26 Jan 2021 22:19:02 GMT) Full text and rfc822 format available.

Message #20 received at 45983 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: zimoun <zimon.toutoune <at> gmail.com>
Cc: 45983 <at> debbugs.gnu.org
Subject: Re: bug#45983: [PATCH 0/3] Fix non-recursive importers gnu and json
Date: Tue, 26 Jan 2021 23:17:56 +0100
zimoun <zimon.toutoune <at> gmail.com> skribis:

> Fixes partially <https://bugs.gnu.org/44115>.
>
> * guix/scripts/import/json.scm (guix-import-json): Handle error.

[...]

> -       (or (json->code file-name)
> -           (leave (G_ "invalid JSON in file '~a'~%") file-name)))
> +       (if (file-exists? file-name)
> +         (or (json->code file-name)
> +             (leave (G_ "invalid JSON in file '~a'~%") file-name))
> +         (leave (G_ "invalid file name~%"))))

I’d suggest this:

  (catch 'system-error
    (lambda ()
      (or (json->code …) …))
    (lambda args
      (leave (G_ "failed to access '~a': ~a~%")
             file-name (strerror (system-error-errno args)))))

This avoids TOCTTOU and gives details about the failure.

Could you send updated patches?

Thanks,
Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#45983; Package guix-patches. (Wed, 27 Jan 2021 23:47:02 GMT) Full text and rfc822 format available.

Message #23 received at 45983 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: 45983 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH v2 2/3] import: gnu: Add internationalized messages.
Date: Thu, 28 Jan 2021 00:46:02 +0100
* guix/import/gnu.scm (gnu->guix-package): Add 'G_' to messages.
---
 guix/import/gnu.scm | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/guix/import/gnu.scm b/guix/import/gnu.scm
index 29324d7554..d307bbbaba 100644
--- a/guix/import/gnu.scm
+++ b/guix/import/gnu.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -17,8 +18,10 @@
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (guix import gnu)
+  #:use-module ((guix diagnostics) #:select (formatted-message))
   #:use-module (guix gnu-maintenance)
   #:use-module (guix import utils)
+  #:use-module (guix i18n)
   #:use-module (guix utils)
   #:use-module (guix store)
   #:use-module (gcrypt hash)
@@ -113,15 +116,16 @@ details.)"
      (let ((version (upstream-source-version release)))
        (match (find-package name)
          (#f
-          (raise (condition
-                  (&message
-                   (message "couldn't find meta-data for GNU package")))))
+          (raise (make-compound-condition
+                  (formatted-message
+                   (G_ "couldn't find meta-data for GNU ~a")
+                   name))))
          (info
           (gnu-package->sexp info release #:key-download key-download)))))
     (_
-     (raise (condition
-             (&message
-              (message
-               "failed to determine latest release of GNU package")))))))
+     (raise (make-compound-condition
+             (formatted-message
+              (G_ "failed to determine latest release of GNU ~a")
+              name))))))
 
 ;;; gnu.scm ends here
-- 
2.29.2





Information forwarded to guix-patches <at> gnu.org:
bug#45983; Package guix-patches. (Wed, 27 Jan 2021 23:47:02 GMT) Full text and rfc822 format available.

Message #26 received at 45983 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: 45983 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH v2 1/3] guix: gnu-maintenance: Fix error handling.
Date: Thu, 28 Jan 2021 00:46:01 +0100
Fixes partially <https://bugs.gnu.org/44115>.

* guix/gnu-maintenance.scm (latest-release): Handle 'ftp-error'.
---
 guix/gnu-maintenance.scm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/guix/gnu-maintenance.scm b/guix/gnu-maintenance.scm
index 08b2bcf758..0da6fc19b6 100644
--- a/guix/gnu-maintenance.scm
+++ b/guix/gnu-maintenance.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2012, 2013 Nikita Karetnikov <nikita <at> karetnikov.org>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -361,7 +362,9 @@ return the corresponding signature URL, or #f it signatures are unavailable."
 
   (let loop ((directory directory)
              (result    #f))
-    (let* ((entries (ftp-list conn directory))
+    (let* ((entries (catch 'ftp-error
+                      (lambda _ (ftp-list conn directory))
+                      (const '())))
 
            ;; Filter out things like /gnupg/patches.  Filter out "w32"
            ;; directories as found on ftp.gnutls.org.

base-commit: d265809b782293eb42dd663b4611ca19dd2bf1b3
-- 
2.29.2





Information forwarded to guix-patches <at> gnu.org:
bug#45983; Package guix-patches. (Wed, 27 Jan 2021 23:47:02 GMT) Full text and rfc822 format available.

Message #29 received at 45983 <at> debbugs.gnu.org (full text, mbox):

From: zimoun <zimon.toutoune <at> gmail.com>
To: 45983 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH v2 3/3] scripts: import: json: Fix error handling.
Date: Thu, 28 Jan 2021 00:46:03 +0100
Fixes partially <https://bugs.gnu.org/44115>.

* guix/scripts/import/json.scm (guix-import-json): Handle error.
---
 guix/scripts/import/json.scm | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/guix/scripts/import/json.scm b/guix/scripts/import/json.scm
index 778e5f4bc5..d8d5c3a4af 100644
--- a/guix/scripts/import/json.scm
+++ b/guix/scripts/import/json.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2014 Eric Bavier <bavier <at> member.fsf.org>
 ;;; Copyright © 2015, 2017 Ricardo Wurmus <rekado <at> elephly.net>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -88,8 +89,13 @@ Import and convert the JSON package definition in PACKAGE-FILE.\n"))
                            (reverse opts))))
     (match args
       ((file-name)
-       (or (json->code file-name)
-           (leave (G_ "invalid JSON in file '~a'~%") file-name)))
+       (catch 'system-error
+         (lambda ()
+           (or (json->code file-name)
+               (leave (G_ "invalid JSON in file '~a'~%") file-name)))
+         (lambda args
+           (leave (G_ "failed to access '~a': ~a~%")
+                  file-name (strerror (system-error-errno args))))))
       (()
        (leave (G_ "too few arguments~%")))
       ((many ...)
-- 
2.29.2





Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Sun, 31 Jan 2021 20:38:02 GMT) Full text and rfc822 format available.

Notification sent to zimoun <zimon.toutoune <at> gmail.com>:
bug acknowledged by developer. (Sun, 31 Jan 2021 20:38:02 GMT) Full text and rfc822 format available.

Message #34 received at 45983-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: zimoun <zimon.toutoune <at> gmail.com>
Cc: 45983-done <at> debbugs.gnu.org
Subject: Re: bug#45983: [PATCH 0/3] Fix non-recursive importers gnu and json
Date: Sun, 31 Jan 2021 21:37:26 +0100
Hi!

I applied the whole series.

zimoun <zimon.toutoune <at> gmail.com> skribis:

> * guix/import/gnu.scm (gnu->guix-package): Add 'G_' to messages.

Two comments: (1) things like (message "string") are already i18n’d, and
(2):

> +     (raise (make-compound-condition
> +             (formatted-message
> +              (G_ "failed to determine latest release of GNU ~a")
> +              name))))))

I removed ‘make-compound-condition’, which is unnecessary here.

Thanks!

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 01 Mar 2021 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 46 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.