ui: 'warn-about-load-error' provides hints for unbound variables.

* guix/ui.scm (warn-about-load-error): Add 'unbound-variable' clause.
* tests/guix-build.sh: Add test.
This commit is contained in:
Ludovic Courtès 2019-07-20 00:33:50 +02:00
parent a2a94b6e58
commit 723bdb8ef0
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 19 additions and 2 deletions

View File

@ -392,6 +392,8 @@ exiting. ARGS is the list of arguments received by the 'throw' handler."
(('syntax-error proc message properties form . rest) (('syntax-error proc message properties form . rest)
(let ((loc (source-properties->location properties))) (let ((loc (source-properties->location properties)))
(warning loc (G_ "~a~%") message))) (warning loc (G_ "~a~%") message)))
(('unbound-variable _ ...)
(report-unbound-variable-error args))
(('srfi-34 obj) (('srfi-34 obj)
(if (message-condition? obj) (if (message-condition? obj)
(warning (G_ "failed to load '~a': ~a~%") (warning (G_ "failed to load '~a': ~a~%")

View File

@ -146,7 +146,7 @@ test `guix build -d --sources=transitive foo \
| wc -l` -eq 3 | wc -l` -eq 3
# Unbound variables. # Unbound variable in thunked field.
cat > "$module_dir/foo.scm" <<EOF cat > "$module_dir/foo.scm" <<EOF
(define-module (foo) (define-module (foo)
#:use-module (guix tests) #:use-module (guix tests)
@ -162,6 +162,21 @@ if guix build package-with-something-wrong -n; then false; else true; fi
guix build package-with-something-wrong -n 2> "$module_dir/err" || true guix build package-with-something-wrong -n 2> "$module_dir/err" || true
grep "unbound" "$module_dir/err" # actual error grep "unbound" "$module_dir/err" # actual error
grep "forget.*(gnu packages base)" "$module_dir/err" # hint grep "forget.*(gnu packages base)" "$module_dir/err" # hint
# Unbound variable at the top level.
cat > "$module_dir/foo.scm" <<EOF
(define-module (foo)
#:use-module (guix tests))
(define-public foo
(dummy-package "package-with-something-wrong"
(build-system gnu-build-system))) ;unbound variable
EOF
guix build sed -n 2> "$module_dir/err"
grep "unbound" "$module_dir/err" # actual error
grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
rm -f "$module_dir"/* rm -f "$module_dir"/*
# Wrong 'define-module' clause reported by 'warn-about-load-error'. # Wrong 'define-module' clause reported by 'warn-about-load-error'.