guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

05/20: squash! Improve error reporting and i18n.


From: guix-commits
Subject: 05/20: squash! Improve error reporting and i18n.
Date: Sun, 4 Jun 2023 17:34:40 -0400 (EDT)

civodul pushed a commit to branch wip-guix-index
in repository guix.

commit 7468f1ccc359e065ca7fb6aa47664681f06ba138
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Apr 2 22:44:12 2023 +0200

    squash! Improve error reporting and i18n.
---
 guix/scripts/index.scm | 43 +++++++++++++++++++------------------------
 po/guix/POTFILES.in    |  1 +
 2 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/guix/scripts/index.scm b/guix/scripts/index.scm
index 731fd418ef..0b4746d6c4 100644
--- a/guix/scripts/index.scm
+++ b/guix/scripts/index.scm
@@ -24,7 +24,8 @@
                           show-bug-report-information
                           with-error-handling
                           string->number*
-                          leave))
+                          display-hint))
+  #:use-module (guix diagnostics)
   #:use-module (guix scripts)
   #:use-module (sqlite3)
   #:use-module (ice-9 match)
@@ -240,15 +241,16 @@ VALUES (:name, :basename, :directory);"
           directories))
        (return #t)))))
 
-(define (insert-packages-with-progress db packages insert-package-fn)
-  "Insert PACKAGES into DB with progress bar report."
-  (let* ((nb-packages (length packages))
-         (prefix      (format #f "Registering ~a packages" nb-packages))
-         (progress    (progress-reporter/bar nb-packages prefix)))
+(define (insert-packages-with-progress db packages insert-package)
+  "Insert PACKAGES into DB with progress bar reporting, calling INSERT-PACKAGE
+for each package to insert."
+  (let* ((count    (length packages))
+         (prefix   (format #f (G_ "indexing ~h packages") count))
+         (progress (progress-reporter/bar count prefix)))
     (call-with-progress-reporter progress
       (lambda (report)
         (for-each (lambda (package)
-                    (insert-package-fn db package)
+                    (insert-package db package)
                     (report))
                   packages)))))
 
@@ -493,8 +495,7 @@ See --database for customization.\n"))
                 (alist-cons 'with-method arg
                             (alist-delete 'with-method result)))
                (_
-                (G_ "guix index: Wrong indexation method, either manifests
- (fast) or store (slow)~%")))))))
+                (leave (G_ "~a: unknown indexing method~%"))))))))
 
 (define %default-options
   `((database . ,user-database-file)
@@ -541,12 +542,6 @@ See --database for customization.\n"))
         (leave (G_ "wrong number of arguments for action '~a'~%")
                action))
 
-      (unless action
-        (format (current-error-port)
-                (G_ "guix index: missing command name~%"))
-        (format (current-error-port)
-                (G_ "Try 'guix index --help' for more information.~%"))
-        (exit 1))
       (alist-cons 'argument (string-concatenate args)
                   (alist-delete 'argument
                                 (alist-cons 'action action
@@ -555,10 +550,7 @@ See --database for customization.\n"))
   (with-error-handling
     (let* ((opts        (parse-command-line args %options
                                             (list %default-options)
-                                            ;; ignore $GUIX_BUILD_OPTIONS
-                                            ;; otherwise, subcommand is not
-                                            ;; detected in the tests context
-                                            #:build-options? #f
+                                            #:build-options? #f ;no builds
                                             #:argument-handler
                                             parse-sub-command))
            (args        (option-arguments opts))
@@ -575,19 +567,22 @@ See --database for customization.\n"))
       (match action
         ('search
          (unless (file-exists? database)
-           (format (current-error-port)
-                   (G_ "guix index: The local cache db does not exist yet.
-You need to index packages first.\nTry 'guix index --help' for more 
information.~%"))
+           (report-error (G_ "file database '~a' does not exist~%")
+                         database)
+           (display-hint (G_ "Run @command{guix index} to create it.  This
+will browse available packages on your system, which may take time."))
            (exit 1))
          (let* ((file (assoc-ref args 'argument))
                 (matches (matching-packages-with-db database file)))
            (print-matching-results matches)
-           (exit (pair? matches))))
+           (or (not (null? matches))
+               (leave (G_ "file '~a' not be found in indexed packages~%")
+                      file))))
         ('index
          (mkdir-p (dirname database))
          ;; Migrate/initialize db to schema at version application-version
          (migrate-schema-to-version database)
          ;; Finally index packages
-         (if (string= with-method "manifests")
+         (if (string=? with-method "manifests")
              (index-packages-from-manifests-with-db database)
              (index-packages-from-store-with-db database)))))))
diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in
index 0431de522b..3c2741057a 100644
--- a/po/guix/POTFILES.in
+++ b/po/guix/POTFILES.in
@@ -163,6 +163,7 @@ guix/scripts/import/opam.scm
 guix/scripts/import/pypi.scm
 guix/scripts/import/stackage.scm
 guix/scripts/import/texlive.scm
+guix/scripts/index.scm
 guix/scripts/offload.scm
 guix/scripts/perform-download.scm
 guix/scripts/refresh.scm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]