Subject: bug#64076: Error message leads user to a false cause of issue

From: Christian Miller <[email-masked]>
Date: Wed, 14 Jun 2023 23:32:11 +0000

If someone imports a module that has code which requires additional modules to be imported but does not do that, the error message will fool the user that he made a mistake with his own defined modules.

cm@gnu /tmp/bug/demo$ guix build -L /tmp -f example.scm
ice-9/eval.scm:223:20: In procedure proc:
error: emacs-dash: unbound variable
hint: Did you forget `(use-modules (bug demo var))'?

I already have it imported but if I run the following command:
cm@gnu /tmp/bug/demo$ guix build -L /tmp -f var.scm
bug/demo/var.scm:14:22: error: git-fetch: unbound variable
hint: Did you forget a `use-modules' form?

We can see that the actual cause of the problem is that in the imported module (var) we forgot to import (guix git-download).

The original command should directly tell that the user.  I am new to Guile Scheme and created a module with some copy/paste since I was just quickly trying something out and thought I did something wrong how I defined those modules.

Example:
/tmp
├── bug
│   └── demo
│       ├── example.scm
│       └── var.scm

// example.scm
(define-module (bug demo example)
  #:use-module (bug demo var)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module (guix build-system emacs)
  #:use-module ((guix licenses) #:prefix license:))

(define-public emacs-solarized-theme
  (package
    (name "emacs-solarized-theme")
    (version "2.0.1")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/bbatsov/solarized-emacs/")
             (commit (string-append "v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32 "0l2lcdm2hsjasfkg4rmypa4mvbhglbkkyv0jg88ygc6py9klcccd"))))
    (build-system emacs-build-system)
    (propagated-inputs
     (list emacs-dash))
    (home-page "https://github.com/bbatsov/solarized-emacs")
    (synopsis "Port of the Solarized theme for Emacs")
    (description
     "Solarized for Emacs is a port of the Solarized theme for Vim.  This
package provides a light and a dark variant.")
    (license license:gpl3+)))

emacs-solarized-theme

// var.scm
(define-module (bug demo var)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  ;;#:use-module (guix git-download)
  #:use-module (guix build-system emacs)
  #:use-module ((guix licenses) #:prefix license:)
  #:export (emacs-dash))

(define-public emacs-dash
  (package
    (name "emacs-dash")
    (version "2.19.1")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/magnars/dash.el")
                    (commit version)))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0z6f8y1m9amhg427iz1d4xcyr6n0kj5w7kmiz134p320ixsdnzd8"))))
    (build-system emacs-build-system)
    (arguments
     (list #:tests? #t
           #:phases
           #~(modify-phases %standard-phases
               (add-after 'unpack 'disable-byte-compile-error-on-warn
                 (lambda _
                   (substitute* "Makefile"
                     (("\\(setq byte-compile-error-on-warn t\\)")
                      "(setq byte-compile-error-on-warn nil)")))))))
    (home-page "https://github.com/magnars/dash.el")
    (synopsis "Modern list library for Emacs")
    (description "This package provides a modern list API library for Emacs.")
    (license license:gpl3+)))

Go to /tmp/bug/demo and run guix build -L /tmp -f example.scm

Note that if you go to var.scm and uncomment line 4, it will build the package.

Also, shouldn't here the correct path be shown where the variable could be imported like it normally does?

demo/var.scm:10:22: error: git-fetch: unbound variable
hint: Did you forget a `use-modules' form?

demo/var.scm:19:18: error: emacs-build-system: unbound variable
hint: Did you forget a `use-modules' form?

Since normally I get the following back:
bug/demo/example.scm:8:3: error: package: unbound variable
hint: Did you forget `(use-modules (guix packages))'?

which makes it really easy to work with it even if you are new to all this stuff.