Subject: Re: bug#32050: invoke (guix build utils) error reporting lacking

From: Maxim Cournoyer <[email-masked]>
Date: Sun, 08 Jul 2018 11:59:25 -0400

Hi Mark,

Mark H Weaver <[email-masked]> writes:

[...]

> Did you check to see if the extraction actually succeeded?
>
> In this case, I don't see how it could have.  When using 'tar' from
> within 'trivial-build-system', you need to add 'bzip2' to PATH, or else
> 'tar' will fail because it can't find 'bzip2'.  There are many examples
> of setting PATH in (gnu packages fonts).

OK. I now understand that the trivial-build-system does exactly nothing
for us, so it doesn't even sets the "PATH" environment variable. This
wasn't obvious to me, thank for pointing it out!

> Changing 'system*' to 'invoke' allowed you to see that something went
> wrong.

Right, my confusion stemmed from the unset PATH variable; tar itself
would return exit code 127 (command not found) in the
trivial-build-system, but I couldn't reproduce directly in a
containerized guix environment because there is a profile generation
hook there which does set the PATH.

>> The error reported by `invoke' isn't accurate, and mutes important
>> output from the program invoked.
>>
>> Example of a failed tar extraction:
>>
>> /gnu/store/xlj36j9dw581iah51iyjgi75iikrj55h-module-import/guix/build/utils.scm:616:6: In procedure invoke:
>> Throw to key `srfi-34' with args `(#<condition &invoke-error
>> [program: "tar" arguments: ("xf"
>> "/gnu/store/yanfzfi7rdyf5scf5h65xbkn7xg0nnbn-docbook-dsssl-doc-1.79.tar.bz2"
>> "--strip-components=1" "-C"
>> "/gnu/store/rw7yzjk1wffza65z6l6rnn25qg97jvh1-docbook-dsssl-doc-1.79"
>> "docbook-dssl-1.79/doc") exit-status: 127 term-signal: #f
>> stop-signal: #f] 68fc80>)'.

It seems that the "system" and "system*" commands of Guile as well as
our "invoke" do preserve the stdout/stderr, as when testing it manually
I can see the useful "sh: tar: command not found" message:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use (guix build utils)
scheme@(guile-user)> (system "tar xf yanfzfi7rdyf5scf5h65xbkn7xg0nnbn-docbook-dsssl-doc-1.79.tar.bz2")
sh: tar: command not found
$1 = 32512
scheme@(guile-user)> (invoke "tar" "xf" "yanfzfi7rdyf5scf5h65xbkn7xg0nnbn-docbook-dsssl-doc-1.79.tar.bz2")
In execvp of tar: No such file or directory
guix/build/utils.scm:616:6: In procedure invoke:
Throw to key `srfi-34' with args `(#<condition &invoke-error [program: "tar" arguments: ("xf" "yanfzfi7rdyf5scf5h65xbkn7xg0nnbn-docbook-dsssl-doc-1.79.tar.bz2") exit-status: 127 term-signal: #f stop-signal: #f] 1e3dc40>)'.

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
--8<---------------cut here---------------end--------------->8---

Unfortunately, when called from the builder side of Guix, this
information seems to be lost:

--8<---------------cut here---------------start------------->8---
./pre-inst-env guix build --no-build-hook --check docbook-dsssl-doc
@ build-started /gnu/store/4ra70nwni8mcjyd2wfx7fqvsl4fpfs5m-docbook-dsssl-doc-1.79.drv - x86_64-linux /var/log/guix/drvs/4r//a70nwni8mcjyd2wfx7fqvsl4fpfs5m-docbook-dsssl-doc-1.79.drv.bz2
Backtrace:
           2 (primitive-load "/gnu/store/kj0nr8i617gjwypalfs065jllhm?")
In ice-9/eval.scm:
   191:35  1 (_ #f)
In /gnu/store/xlj36j9dw581iah51iyjgi75iikrj55h-module-import/guix/build/utils.scm:
    616:6  0 (invoke _ . _)

/gnu/store/xlj36j9dw581iah51iyjgi75iikrj55h-module-import/guix/build/utils.scm:616:6: In procedure invoke:
Throw to key `srfi-34' with args `(#<condition &invoke-error [program: "tar" arguments: ("-xf" "/gnu/store/yanfzfi7rdyf5scf5h65xbkn7xg0nnbn-docbook-dsssl-doc-1.79.tar.bz2" "--strip-components=1" "--no-same-owner" "-C" "/gnu/store/ppf9bhzyqphmc9cvwhq8pc3yfir2qd3m-docbook-dsssl-doc-1.79" "docbook-dsssl-1.79/doc") exit-status: 127 term-signal: #f stop-signal: #f] 68fcc0>)'.
builder for `/gnu/store/4ra70nwni8mcjyd2wfx7fqvsl4fpfs5m-docbook-dsssl-doc-1.79.drv' failed with exit code 1
@ build-failed /gnu/store/4ra70nwni8mcjyd2wfx7fqvsl4fpfs5m-docbook-dsssl-doc-1.79.drv - 1 builder for `/gnu/store/4ra70nwni8mcjyd2wfx7fqvsl4fpfs5m-docbook-dsssl-doc-1.79.drv' failed with exit code 1
guix build: error: build failed: build of
`/gnu/store/4ra70nwni8mcjyd2wfx7fqvsl4fpfs5m-docbook-dsssl-doc-1.79.drv'
failed
--8<---------------cut here---------------end--------------->8---

Could it be preserved? It'd be very useful when debugging :)

Maxim