Le 2017-11-07 13:52, Hartmut Goebel a écrit :
Am 07.11.2017 um 12:05 schrieb julien lepiller:
Since we encourage users to use use-package-modules etc, I think it's
better
to catch this error and explain it to users as soon as it happens.
It's more
friendly for users than a troubleshooting section in the manual.

+1
Thanks for proposing a patch so quickly!

Package module "abc" does not exist.
ERROR: In procedure scm-error:
ERROR: check "use-package-modules" line in your configuration.

For me this looks confusing: The actual error message is not prefixed by "ERROR:". Also (nitpicking) the explanation could by a bit more verbose.
Like this:

ERROR: In procedure scm-error:
ERROR: Package module "abc" does not exist.
ERROR: Please check the "use-package-modules" line in your configuration.

It would even be better is the fist line would not refer to "procedure
scm-error", but to the config actually processed (and even the line in
there). But nevertheless this patch is a big improvement already.

This new version outputs something like this :


guix system: error: failed to load 'vm-image.tmpl':
vm-image.tmpl:6:0: vm-image.tmpl:6:0: Package module "abc" does not exist.
Check the "use-package-modules" line in your configuration.


Previously I tested in in the REPL, hence no filename. This time I
modified vm-image.tmpl to add an "abc" package, and ran
"guix system vm vm-image.tmpl".
From 334852e5cd7f526c93b2ad7061bd56c0326d136f Mon Sep 17 00:00:00 2001
From: Julien Lepiller <jul...@lepiller.eu>
Date: Tue, 7 Nov 2017 11:46:34 +0100
Subject: [PATCH] Catch use-modules errors in configuration.

* gnu.scm (use-package-modules, use-service-modules, use-system-modules):
Catch use-modules errors and show a small explanation about it.
---
 gnu.scm | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/gnu.scm b/gnu.scm
index 913ce6160..3de04fd8a 100644
--- a/gnu.scm
+++ b/gnu.scm
@@ -52,13 +52,32 @@
                   (module-use! i (resolve-interface m))))
               %public-modules)))
 
+(define (import-error type module syntax)
+  (error (string-append
+           type " module \"" module "\" does not exist.\n"
+           "Check the \"" syntax "\" line in your configuration.")))
+
 (define-syntax-rule (use-package-modules module ...)
-  (use-modules (gnu packages module) ...))
+  (begin
+    (catch #t (lambda () (use-modules (gnu packages module)))
+           (lambda _
+             (import-error "Package" (symbol->string 'module) "use-package-modules")))
+    ...))
 
 (define-syntax-rule (use-service-modules module ...)
-  (use-modules (gnu services module) ...))
+  (begin
+    (catch #t (lambda () (use-modules (gnu services module)))
+           (lambda _
+             (import-error "Service" (symbol->string 'module) "use-service-modules")))
+    ...))
+
 
 (define-syntax-rule (use-system-modules module ...)
-  (use-modules (gnu system module) ...))
+  (begin
+    (catch #t (lambda () (use-modules (gnu system module)))
+           (lambda _
+             (import-error "System" (symbol->string 'module) "use-system-modules")))
+    ...))
+
 
 ;;; gnu.scm ends here
-- 
2.13.6

Reply via email to