unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: Ricardo Wurmus <rekado@elephly.net>
Cc: guix-devel@gnu.org
Subject: Re: better error messages through assertions
Date: Fri, 25 Feb 2022 13:55:46 -0500	[thread overview]
Message-ID: <875yp2zsgd.fsf@gmail.com> (raw)
In-Reply-To: <87ilthoxvu.fsf@elephly.net> (Ricardo Wurmus's message of "Mon, 14 Feb 2022 23:32:22 +0100")

Hello Ricardo,

Ricardo Wurmus <rekado@elephly.net> writes:

> Hi Guix,
>
> today on IRC someone reported an ugly error message when reconfiguring
> their system:
>
> Backtrace:
>           18 (primitive-load "/home/me/.config/guix/current/bin/…")
> In guix/ui.scm:
>    2209:7 17 (run-guix . _)
>   2172:10 16 (run-guix-command _ . _)
> In ice-9/boot-9.scm:
>   1752:10 15 (with-exception-handler _ _ #:unwind? _ # _)
> In guix/status.scm:
>     822:3 14 (_)
>     802:4 13 (call-with-status-report _ _)
> In guix/scripts/system.scm:
>    1256:4 12 (_)
> In ice-9/boot-9.scm:
>   1752:10 11 (with-exception-handler _ _ #:unwind? _ # _)
> In guix/store.scm:
>    658:37 10 (thunk)
>    1320:8  9 (call-with-build-handler #<procedure 7fecaf8570c0 at g…> …)
>   2123:24  8 (run-with-store #<store-connection 256.99 7fecb75c7230> …)
> In guix/scripts/system.scm:
>     827:2  7 (_ _)
>     703:7  6 (_ #<store-connection 256.99 7fecb75c7230>)
> In gnu/system.scm:
>   1227:19  5 (operating-system-derivation _)
> In gnu/services.scm:
>    1091:6  4 (instantiate-missing-services _)
> In srfi/srfi-1.scm:
>    460:18  3 (fold #<procedure 7fecb73c0960 at gnu/services.scm:109…> …)
> In gnu/services.scm:
>   1092:27  2 (_ (#<<service> type: #<service-type gdm 7fecbd17f6…> …) …)
> 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:
> In procedure struct-vtable: Wrong type argument in position 1 (expecting struct):
>
> As you can probably tell easily by looking at this message, the
> “service” field of the operating system configuration looked something
> like this:
>
>   (services (append (list a b c %desktop-services) #;oops))
>
> instead of this
>
>   (services (append (list a b c) %desktop-services))
>
> This is because INSTANTIATE-MISSING-SERVICES — and FOLD-SERVICES, and
> many more — assumes that it is only passed a plain list of services.  It
> then proceeds to call SERVICE-KIND on what may or may not be a service.
>
> I think we should add simple type checks, something like this:
>
>   (define (listof pred)
>     (lambda (thing)
>      (and (list? thing) (every pred thing))))
>   …
>   (define (assert-type type-check thing message)
>     (or (false-if-exception (type-check thing))
>         (report-error (G_ "type error: …\n" message))))
>
>   ;; Use ASSERT-TYPE in an example procedure.
>   (define (do-something-with-services services)
>     (assert-type (listof service?) services
>                  "SERVICES must be a list of <service> values.")
>
>     ;; Do things…
>     (map service-kind services))
>
> What do you think?  There are many different ways of implementing this
> (a new variant of DEFINE that also accepts a type declaration, an assert
> like above, a fancier assert that composes a helpful error message by
> itself, a separate type declaration that is looked up only when the
> corresponding procedure is called in a certain context, etc), but I’d
> first like to know if there is consensus that we want something like
> this.

I hear we now have "field sanitizers" on Guix records; without having
dug the details, it seems to be we could add a predicate validating the
input there?  The nice thing about it is that it'd be a one place
change, instead of asserts to sprinkle around various places.

Thanks,

Maxim


  parent reply	other threads:[~2022-02-25 18:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-14 22:32 better error messages through assertions Ricardo Wurmus
2022-02-15  8:48 ` Maxime Devos
2022-02-15 21:45 ` Philip McGrath
2022-02-15 22:15   ` Ricardo Wurmus
2022-02-28 12:59     ` Ludovic Courtès
2022-02-28 16:18       ` Philip McGrath
2022-03-07 10:13         ` Ludovic Courtès
2022-03-28 20:25           ` Philip McGrath
2022-03-30  9:37             ` Ludovic Courtès
2022-03-30 13:28               ` Andy Wingo
2022-04-01  8:47                 ` Ludovic Courtès
2022-04-01 19:28                 ` Philip McGrath
2022-04-05 12:04                   ` Ludovic Courtès
2022-04-01 19:47               ` Philip McGrath
2022-02-22  4:31 ` Arun Isaac
2022-02-25 18:55 ` Maxim Cournoyer [this message]
2022-02-26 13:33   ` Ricardo Wurmus
2022-02-26 13:51     ` Maxim Cournoyer
2022-02-28 13:02     ` Ludovic Courtès
2022-02-28 16:00       ` Maxim Cournoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875yp2zsgd.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=guix-devel@gnu.org \
    --cc=rekado@elephly.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).