unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / Atom feed
* [bug#43458] [PATCH] guix: build: Add a hint for unspecified value
@ 2020-09-16 21:40 Julien Lepiller
  2020-09-18 20:35 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: Julien Lepiller @ 2020-09-16 21:40 UTC (permalink / raw)
  To: 43458

[-- Attachment #1: Type: text/plain, Size: 1284 bytes --]

Hi Guix!

this patch adds a hint to guix build, when you try to build from a file
and it returns #<unspecified>.  The most common error is when you copy
the structure from other guix modules and use `define-public` for your
package. The file returns #<unspecified> and you get this message:

> #<unspecified>: not something we can build.

Which is not very helpful. Here is what happens with this change:

> guix build: error: #<unspecified>: not something we can build
> 
> hint: If you build from a file, make sure the last scheme expression
> returns a package value.  `define-public' defines a variable, but
> returns #<unspecified>.  To fix this, add a scheme expression at the
> end of the file that consists only of the package's variable name you
> defined.  ex:
> 
>      (define-public my-package
>        (package
>          ...))
>      
>      my-package

If instead, you return a value that is not understood, the message is
simpler (as this is not something that happens out of confusion / being
new to guix or guile):

> guix build: error: 1: not something we can build
> 
> hint: If you build from a file, make sure the last scheme expression
> returns a package, gexp, derivation value or a list of such values.

(here the file returned "1" which we can't build :))

[-- Attachment #2: 0001-guix-build-Add-a-hint-for-unspecified-value.patch --]
[-- Type: text/x-patch, Size: 2272 bytes --]

From b29a325ef52d402c9618bfe9f02e478134297c0f Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Wed, 16 Sep 2020 23:32:00 +0200
Subject: [PATCH] guix: build: Add a hint for unspecified value.

* guix/scripts/build.scm (options->things-to-build): Add a hint when we
cannot build something.
---
 guix/scripts/build.scm | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 25418661b9..46d1415a4d 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -38,6 +38,7 @@
   #:use-module (guix monads)
   #:use-module (guix gexp)
   #:use-module (guix profiles)
+  #:use-module (guix diagnostics)
   #:autoload   (guix http-client) (http-fetch http-get-error?)
   #:use-module (ice-9 format)
   #:use-module (ice-9 match)
@@ -46,6 +47,7 @@
   #:use-module (srfi srfi-11)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35)
   #:use-module (srfi srfi-37)
   #:use-module (gnu packages)
   #:autoload   (guix download) (download-to-store)
@@ -805,7 +807,27 @@ must be one of 'package', 'all', or 'transitive'~%")
 build---packages, gexps, derivations, and so on."
   (define (validate-type x)
     (unless (or (derivation? x) (file-like? x) (gexp? x) (procedure? x))
-      (leave (G_ "~s: not something we can build~%") x)))
+      (raise (make-compound-condition
+               (formatted-message (G_ "~s: not something we can build~%") x)
+               (condition
+                (&fix-hint
+                 (hint
+                   (if (unspecified? x)
+                       (G_ "If you build from a file, make sure the last scheme
+expression returns a package value.  @code{define-public} defines a variable,
+but returns #<unspecified>.  To fix this, add a scheme expression at the end of
+the file that consists only of the package's variable name you defined. ex:
+
+@example
+(define-public my-package
+  (package
+    ...))
+
+my-package
+@end example")
+                       (G_ "If you build from a file, make sure the last scheme
+expression returns a package, gexp, derivation value or a list of such
+values.")))))))))
 
   (define (ensure-list x)
     (let ((lst (match x
-- 
2.28.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [bug#43458] [PATCH] guix: build: Add a hint for unspecified value
  2020-09-16 21:40 [bug#43458] [PATCH] guix: build: Add a hint for unspecified value Julien Lepiller
@ 2020-09-18 20:35 ` Ludovic Courtès
  2020-09-29 13:16   ` bug#43458: " Julien Lepiller
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2020-09-18 20:35 UTC (permalink / raw)
  To: Julien Lepiller; +Cc: 43458

Julien Lepiller <julien@lepiller.eu> skribis:

>>From b29a325ef52d402c9618bfe9f02e478134297c0f Mon Sep 17 00:00:00 2001
> From: Julien Lepiller <julien@lepiller.eu>
> Date: Wed, 16 Sep 2020 23:32:00 +0200
> Subject: [PATCH] guix: build: Add a hint for unspecified value.
                   ^
I tend to use “guix build:” as the prefix for this file.

> * guix/scripts/build.scm (options->things-to-build): Add a hint when we
> cannot build something.

Great idea!

> +      (raise (make-compound-condition
> +               (formatted-message (G_ "~s: not something we can build~%") x)
> +               (condition
> +                (&fix-hint
> +                 (hint
> +                   (if (unspecified? x)
> +                       (G_ "If you build from a file, make sure the last scheme
> +expression returns a package value.  @code{define-public} defines a variable,
> +but returns #<unspecified>.  To fix this, add a scheme expression at the end of
               ^
@code

> +the file that consists only of the package's variable name you defined. ex:

s/. ex:/as in this example:/

> +@example
> +(define-public my-package
> +  (package
> +    ...))
> +
> +my-package
> +@end example")
> +                       (G_ "If you build from a file, make sure the last scheme
> +expression returns a package, gexp, derivation value or a list of such
> +values.")))))))))

s/derivation value/derivation/

Also s/scheme/Scheme/ throughout.

OK with these changes, thank you!

Ludo’.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#43458: [PATCH] guix: build: Add a hint for unspecified value
  2020-09-18 20:35 ` Ludovic Courtès
@ 2020-09-29 13:16   ` Julien Lepiller
  0 siblings, 0 replies; 3+ messages in thread
From: Julien Lepiller @ 2020-09-29 13:16 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 43458-done

Pushed as e75443d4f28ff1aa97e545f2b47b311c3a5ac32a, thanks for the
review!




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-29 13:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16 21:40 [bug#43458] [PATCH] guix: build: Add a hint for unspecified value Julien Lepiller
2020-09-18 20:35 ` Ludovic Courtès
2020-09-29 13:16   ` bug#43458: " Julien Lepiller

unofficial mirror of guix-patches@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guix-patches/1 guix-patches/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guix-patches guix-patches/ https://yhetil.org/guix-patches \
		guix-patches@gnu.org
	public-inbox-index guix-patches

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://news.yhetil.org/yhetil.gnu.guix.patches


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git