Le 2017-11-07 16:59, myglc2 a écrit :
On 11/07/2017 at 15:52 julien lepiller writes:

Maybe that's too much?

Not for me. Looks great! Just a couple minor suggestions:

1) How about narrowing search to locations like this:

Hint: You may use `guix package --show=foo | grep location` to search
for foo's location.

Oh, I didn't know this option, good idea, thanks :D


2) I think you mean to say "foo" where you say "ssh" in the last two HINTs

You're right, though I prefer to use "bar" to show there is no relation between
the package name and its module.

I added "[PATCH]" to the subject to get others look at this message. I plan to push it in a few days unless it gets more comments. If an experienced schemer
could look at that, I'm sure the coding style could be improved a lot ;)
From e092725c05625f1b6c5705177b3f080471611e85 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 | 42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/gnu.scm b/gnu.scm
index 913ce6160..1ae5f2d1d 100644
--- a/gnu.scm
+++ b/gnu.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <l...@gnu.org>
 ;;; Copyright © 2015 Joshua S. Grant <jgr...@parenthetical.io>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othac...@gmail.com>
+;;; Copyright © 2017 Julien Lepiller <jul...@lepiller.eu>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -52,13 +53,48 @@
                   (module-use! i (resolve-interface m))))
               %public-modules)))
 
+(define (import-error type module syntax)
+  (define package-hint
+    (string-append
+      "Hint: You may use `guix package --show=foo | grep location` to search\n"
+      "Hint: for foo's location.\n"
+      "Hint: If you get the line \"location: gnu/packages/bar.scm:174:2\",\n"
+      "Hint: you want to add bar in use-package-modules."))
+  (define service-hint
+    (string-append
+      "Hint: You may use `guix system search foo` to search for foo's location.\n"
+      "Hint: If you get the line \"location: gnu/services/bar.scm:188:2\",\n"
+      "Hint: you want to add bar in use-service-modules."))
+  (error (string-append
+           type " module \"" module "\" does not exist.\n"
+           "Check the \"" syntax "\" line in your configuration.\n"
+           (if (equal? type "Package")
+               package-hint
+               (if (equal? type "Service")
+                   service-hint
+                   "")))))
+
 (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