Subject: Re: bug#28240: bad backtrace on “guix archive-x”

From: zimoun <[email-masked]>
Date: Fri, 28 Oct 2022 10:08:49 +0200

Hi Ricardo,

On Thu, 27 Oct 2022 at 13:30, Ricardo Wurmus <[email-masked]> wrote:
> zimoun <[email-masked]> writes:
>
>>> guix archive: error: corrupt input while restoring '/tmp/ci' from #<input: file 0>
>>
>> The situation is still the same.  Well, is the “guix archive” error the
>> point of this bug report?
>
> The point is the terrible backtrace.  While this error is a little
> better it’s also not great.

About lzip, the error is catched by call-with-error-handling (guix ui),

--8<---------------cut here---------------start------------->8---
             ((nar-error? c)
              (let ((file (nar-error-file c))
                    (port (nar-error-port c)))
                (if file
                    (leave (G_ "corrupt input while restoring '~a' from ~s~%")
                           file (or (port-filename* port) port))
                    (leave (G_ "corrupt input while restoring archive from ~s~%")
                           (or (port-filename* port) port)))))
--8<---------------cut here---------------end--------------->8---

> But my primary concern is to prevent ’guix archive’ from printing a bad
> backtrace.  Doesn’t matter what we feed it.

In the case of gzip,

--8<---------------cut here---------------start------------->8---
Backtrace:
          12 (primitive-load "/home/simon/.config/guix/current/bin/guix")
In guix/ui.scm:
   2263:7 11 (run-guix . _)
  2226:10 10 (run-guix-command _ . _)
In ice-9/boot-9.scm:
  1752:10  9 (with-exception-handler _ _ #:unwind? _ #:unwind-for-type _)
In guix/status.scm:
    835:3  8 (_)
    815:4  7 (call-with-status-report _ _)
In ice-9/boot-9.scm:
  1752:10  6 (with-exception-handler _ _ #:unwind? _ #:unwind-for-type _)
In guix/store.scm:
   656:37  5 (thunk)
   1295:8  4 (call-with-build-handler #<procedure 7f6aab46c7e0 at guix/ui.scm:1171:2 (continue store things mo…> …)
In guix/serialization.scm:
   416:21  3 (fold-archive #<procedure 7f6aab8f5d20 at guix/serialization.scm:512:16 (file type content result)> …)
In unknown file:
           2 (utf8->string #vu8(0 3 236 189 13 120 92 87 121 46 58 182 147 96 13 73 228 144 244 212 64 40 59 # …))
In ice-9/boot-9.scm:
  1685:16  1 (raise-exception _ #:continuable? _)
  1685:16  0 (raise-exception _ #:continuable? _)

ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Throw to key `decoding-error' with args `("scm_from_utf8_stringn" "input locale conversion error" 0 #vu8
--8<---------------cut here---------------end--------------->8---

the error is incorrectly handled.  If I read correctly, the handled
errors are,

      (guard* (c ((package-input-error? c)
                  ((package-cross-build-system-error? c)
                  ((gexp-input-error? c)
                  ((profile-not-found-error? c)
                  ((missing-generation-error? c)
                  ((unmatched-pattern-error? c)
                  ((profile-collision-error? c)
                  ((nar-error? c)
                  ((store-connection-error? c)
                  ((store-protocol-error? c)
                  ((derivation-missing-output-error? c)
                  ((file-search-error? c)
                  ((invoke-error? c)
                   ((formatted-message? c)
                   ((message-condition? c)

so this ’decoding-error’ is not handled earlier.  Well, the only catch
of ’decoding-error’ is by maybe-utf8->string from (guix status).

Cheers,
simon