[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
- 04/20: squash! "--db-path" -> "--database"., (continued)
- 04/20: squash! "--db-path" -> "--database"., guix-commits, 2023/06/04
- 07/20: squash! Don't insert directory if it's already present., guix-commits, 2023/06/04
- 08/20: squash! Remove debugging statements., guix-commits, 2023/06/04
- 12/20: squash! Add one variant of each package (name/version pair)., guix-commits, 2023/06/04
- 13/20: squash! Create database when it doesn't already exist., guix-commits, 2023/06/04
- 16/20: squash! Simplify '--help'., guix-commits, 2023/06/04
- 18/20: squash! Optimize 'insert-package'., guix-commits, 2023/06/04
- 19/20: squash! Show output name except for "out"; remove '-d'., guix-commits, 2023/06/04
- 02/20: DRAFT Add 'guix index'., guix-commits, 2023/06/04
- 03/20: squash! Update test., guix-commits, 2023/06/04
- 05/20: squash! Improve error reporting and i18n.,
guix-commits <=
- 01/20: store: Tolerate non-existent GC root directories., guix-commits, 2023/06/04
- 06/20: squash! "with-method" -> "method", guix-commits, 2023/06/04
- 09/20: squash! Choose system-wide database if it's more recent., guix-commits, 2023/06/04
- 11/20: squash! Keep store prefix in database., guix-commits, 2023/06/04
- 15/20: squash! Rename to 'guix locate'., guix-commits, 2023/06/04
- 17/20: squash! Migrate schema when opening., guix-commits, 2023/06/04
- 20/20: squash! Document., guix-commits, 2023/06/04
- 10/20: squash! Do not insert the same directory more than once., guix-commits, 2023/06/04
- 14/20: squash! Remove actions; auto-update database when needed., guix-commits, 2023/06/04