Subject: [wishlist] Improve packaging error handling and tooling

From: "pelzflorian (Florian Pelz)" <[email-masked]>
Date: Wed, 22 May 2019 23:54:49 +0200

I believe for package definitions

* known triggers for unhelpful error messages should get more graceful
  error messages,

* there should be no fixed truncation of error messages and

* there could perhaps be more tooling like single-stepping through the
  build process.

For example in <https://issues.guix.info/issue/35640> I got an
unhelpful error message:

[ 11%] LOAD     guix/scripts/search.scm
[ 11%] LOAD     guix/scripts/gc.scm
[ 11%] LOAD     guix/scripts/hash.scm
[ 11%] LOAD     guix/scripts/pack.scm
Backtrace:
In ice-9/boot-9.scm:
   222:29 19 (map1 (((guix utils)) ((guix store)) ((guix #) # (#)) …))
   222:29 18 (map1 (((guix store)) ((guix status) #:select (#)) (#) …))
   222:29 17 (map1 (((guix status) #:select (#)) ((guix grafts)) # …))
   222:29 16 (map1 (((guix grafts)) ((guix monads)) ((guix #)) (#) …))
   222:29 15 (map1 (((guix monads)) ((guix modules)) ((guix #)) (#) …))
   222:29 14 (map1 (((guix modules)) ((guix packages)) ((guix #)) # …))
   222:29 13 (map1 (((guix packages)) ((guix profiles)) ((guix #)) …))
   222:29 12 (map1 (((guix profiles)) ((guix describe)) ((guix #)) …))
   222:29 11 (map1 (((guix describe)) ((guix derivations)) ((# #)) …))
   222:29 10 (map1 (((guix derivations)) ((guix search-paths)) (#) …))
   222:29  9 (map1 (((guix search-paths)) ((guix build-system #)) # …))
   222:29  8 (map1 (((guix build-system gnu)) ((guix scripts #)) # …))
   222:29  7 (map1 (((guix scripts build)) ((guix self) #:select …) …))
   222:29  6 (map1 (((guix self) #:select (make-config.scm)) ((…)) …))
   222:29  5 (map1 (((gnu packages)) ((gnu packages bootstrap)) (…) …))
   222:29  4 (map1 (((gnu packages bootstrap)) ((gnu packages …) …) …))
   222:17  3 (map1 (((gnu packages compression) #:hide (zip)) ((…)) …))
  2830:10  2 (resolve-interface (gnu packages compression) #:select _ …)
   260:13  1 (for-each #<procedure 52470e0 at ice-9/boot-9.scm:2830…> …)
In unknown file:
           0 (scm-error misc-error #f "~A" ("no binding `zip' to h…") …)

ERROR: In procedure scm-error:
no binding `zip' to hide in module (gnu packages compression)

I wished it had been possible to step (or reverse-step) through the
build process like in gdb for C programs, but I presume this might be
too difficult to realize for now (?).

Then the following was a non-obvious error I got when building an
earlier revision of usb-modeswitch-data because I used #:modules (…
(guix packages)) in the arguments to the trivial-build-system of
usb-modeswitch-data.

florian@florianmacbook ~/git/guix [env]$ bzcat /var/log/guix/drvs/pz/z8vjc5ba6slfry3jipczlvv84ww5j3-module-import-compiled.drv.bz2
Backtrace:
In system/base/compile.scm:
    152:6 19 (compile-file "/gnu/store/6mww1gn4l70m4j4psj5966w0jdsi?" ?)
     43:4 18 (call-once _)
In ice-9/boot-9.scm:
    841:4 17 (with-throw-handler _ _ _)
In system/base/compile.scm:
    59:11 16 (_)
   155:11 15 (_ #<closed: file 8dc5b0>)
   235:18 14 (read-and-compile #<input: /gnu/store/6mww1gn4l70m4j4p?> ?)
   183:32 13 (compile-fold (#<procedure compile-tree-il (x e opts)>) ?)
In ice-9/boot-9.scm:
   2312:4 12 (save-module-excursion #<procedure a16c00 at language/s?>)
In language/scheme/compile-tree-il.scm:
    31:15 11 (_)
In ice-9/psyntax.scm:
  1235:36 10 (expand-top-sequence ((define-module (guix #) # (?) ?)) ?)
  1182:24  9 (parse _ (("placeholder" placeholder)) ((top) #(# # ?)) ?)
   285:10  8 (parse _ (("placeholder" placeholder)) (()) _ c&e (# #) #)
In ice-9/eval.scm:
   293:34  7 (_ #<module (#{ g3136}#) 8f78c0>)
In ice-9/boot-9.scm:
   2874:4  6 (define-module* _ #:filename _ #:pure _ #:version _ # _ ?)
  2071:24  5 (call-with-deferred-observers #<procedure 12a0aa0 at ic?>)
  2887:24  4 (_)
   222:17  3 (map1 (((guix utils)) ((guix records)) ((guix store)) ?))
   2803:6  2 (resolve-interface _ #:select _ #:hide _ #:prefix _ # _ ?)
In unknown file:
           1 (scm-error misc-error #f "~A ~S" ("no code for modu?" ?) ?)
In ice-9/boot-9.scm:
   752:25  0 (dispatch-exception _ _ _)

ice-9/boot-9.scm:752:25: In procedure dispatch-exception:
no code for module (guix utils)

When I did `./pre-inst-env guix lint usb-modeswitch-data`, it did not
find the error either.

Regards,
Florian