summary refs log tree commit diff
diff options
context:
space:
mode:
authorzimoun <zimon.toutoune@gmail.com>2021-01-28 00:46:03 +0100
committerLudovic Courtès <ludo@gnu.org>2021-01-31 21:49:59 +0100
commit60947257aeb24431ea397829c8ea49a7e26b807d (patch)
tree824d96627012fe5bffb3f81d1ad249a92c89e8d9
parent460e7d8bc9fd06699c19d998605cf163575b247c (diff)
downloadguix-60947257aeb24431ea397829c8ea49a7e26b807d.tar.gz
scripts: import: json: Fix error handling.
Fixes partially <https://bugs.gnu.org/44115>.

* guix/scripts/import/json.scm (guix-import-json): Handle error.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
-rw-r--r--guix/scripts/import/json.scm10
1 files 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@member.fsf.org>
 ;;; Copyright © 2015, 2017 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune@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 ...)