From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id eBOtK0wmGWI5AgEAgWs5BA (envelope-from ) for ; Fri, 25 Feb 2022 19:56:12 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id MK1sJEwmGWJ4PAAAG6o9tA (envelope-from ) for ; Fri, 25 Feb 2022 19:56:12 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3ADE739A8F for ; Fri, 25 Feb 2022 19:56:12 +0100 (CET) Received: from localhost ([::1]:44112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNflB-0003xd-Uv for larch@yhetil.org; Fri, 25 Feb 2022 13:56:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNfkt-0003vg-Gc for guix-devel@gnu.org; Fri, 25 Feb 2022 13:55:51 -0500 Received: from [2607:f8b0:4864:20::f31] (port=39854 helo=mail-qv1-xf31.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNfkq-0005pD-Lk for guix-devel@gnu.org; Fri, 25 Feb 2022 13:55:51 -0500 Received: by mail-qv1-xf31.google.com with SMTP id a1so7418702qvl.6 for ; Fri, 25 Feb 2022 10:55:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=jGv3EHAvWlw7tmXKEIKlDVmTku5NdYsJJ/zohJKYUYI=; b=p/QyhLevCksx/wkd7MhcyE4TYRymbNLEyaXV7nX1+8hYiBMmudmg7uUViyLnTR9HDz tBbQXKMonOsvaSV35dT2VBWkgS1yx8YOap3YoSHhP0orazh4nINwl3ssgu5J3HyVW1sN qcHw+rcOtecmGdOxWPWVIBzEyB3GeWT8BpOXdIZGozf0CoC2m2xW9ymGZnNr0HpNVMpx FveLGIwzdB9JrphOVFJZKW+Ypl5CjtDbTqAR93oywEWerQa7y+bOrzGLTl1d1vk0gBdP DnibSfz/dMWr0wQLwymrafsSYyItjYMlFHvGpIMWR0OjAZ1BChp+GEtZLO1y8IXmI1CJ IjwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=jGv3EHAvWlw7tmXKEIKlDVmTku5NdYsJJ/zohJKYUYI=; b=v+dpKQja6dVqKAP/7NT6GjvAF/5Usz9BRT9Gwlt7jb/O/uQ5IswHZlSlZJdWj0fBMT s29R9Js2EAX3NI1mqx5vXFXiTLjQNkZtaETfWczKSXIzL2VN4EXQvKTAz115qoN2mmx+ YMhVUL+/EAm5J7mhOp2IIp5rUGpOUbO4v6SZJQpc/CgcjwNXCpORQcYc3fIvzJ5hsEiH uTvIUU9AIYP8scR/7PJKd3XmfCV7JM24mFFBi0NjBFlErkWkBpYVrd4OIFWe8vkMZGID fhK2Ydrko2ZIKzj2WmPnoq+IEQtvHB2w+/cf8JzsdcXk99ijty6lrId/dIxwghhaqUoN /g8w== X-Gm-Message-State: AOAM533FAMWuL2zieJiBzlHe7f3oajRm/CF3/fxEdwv2OUYRVizYdJZL 1prpV4HBUeaQ3ZZo+Tw/+2k10vnuF3s= X-Google-Smtp-Source: ABdhPJz2LVXeeInE2c9Sbuc94p5lbBcA11XA1ECRpOzl5aSbtodhnWhCIXYQ8MrSYeRWbFPCAzPHnQ== X-Received: by 2002:ad4:574a:0:b0:42b:ef56:c2a4 with SMTP id q10-20020ad4574a000000b0042bef56c2a4mr7096164qvx.16.1645815347682; Fri, 25 Feb 2022 10:55:47 -0800 (PST) Received: from hurd (dsl-149-67.b2b2c.ca. [66.158.149.67]) by smtp.gmail.com with ESMTPSA id l7-20020a37f507000000b0047b528ef416sm1542882qkk.93.2022.02.25.10.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 10:55:47 -0800 (PST) From: Maxim Cournoyer To: Ricardo Wurmus Subject: Re: better error messages through assertions References: <87ilthoxvu.fsf@elephly.net> Date: Fri, 25 Feb 2022 13:55:46 -0500 In-Reply-To: <87ilthoxvu.fsf@elephly.net> (Ricardo Wurmus's message of "Mon, 14 Feb 2022 23:32:22 +0100") Message-ID: <875yp2zsgd.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::f31 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::f31; envelope-from=maxim.cournoyer@gmail.com; helo=mail-qv1-xf31.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: guix-devel@gnu.org Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1645815372; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=jGv3EHAvWlw7tmXKEIKlDVmTku5NdYsJJ/zohJKYUYI=; b=LYWT8xBbgk1eqzW6VSBvrzWDVxjMCzGyL3Fv39iBNT1FFV1ln/qd8PTBxjnML3nUzW51LE dHwHhWuLvpgXbYYVMPhG7oSGAjbYsc3bBRVYR8g39BhmBAfwOrkqa3hLFEvclpNOrv7XSu LjtbI4v2IPoV+Gf973btb682gRcd6BMH0REPSiD1hT+0Q7EstnCqbS1yBa4nnhYGJvJVM2 63IDMNcjI5qbLpDeGYmx82QMQeysTUrXZXXLdq1g1yDz2rL7DYffnGTErXnUNOvnb4c8V6 aU4ieIBtfYqsXNl89bxEW0sdsj+g6tly9dduGIQJPXBQj//kSMDzyl1v+o5PJg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1645815372; a=rsa-sha256; cv=none; b=Csz/oz/+g/Ql+odDxZdpc4AwFSh3mEzp3XGCs3+hi7udDnq6ns48ROJsmys7BxN0ck/2FZ rZnsrPd09CAAAB1cyfYw2UWm/XDLglb5l7MHqCstWHKNiQ8fk0dwQ5fBA5uM6tPRpa1lI/ woFQKFZA8ssd6MN4l/X2pIJBJ+R15WGp0gSt4o1yo7oxWTt1b9aYi+SSpyXJScz2vrsPOt BwoN0aV2DHG0ji8SpeDlLTBwjyVlep+GDSxV/vvjlUPsZI+e6c0553JhZZeekT0MOQzJNb TCh75w/nt2zjKlE9SzEuwbe2LBckHEJdSKABFy6ka68PYdK75NpDfQN+ksUGLg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="p/QyhLev"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -9.33 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="p/QyhLev"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 3ADE739A8F X-Spam-Score: -9.33 X-Migadu-Scanner: scn0.migadu.com X-TUID: t86G3wQZ+nGw Hello Ricardo, Ricardo Wurmus 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/=E2=80=A6= ") > 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 # =E2=80=A6) > 2123:24 8 (run-with-store # =E2= =80=A6) > In guix/scripts/system.scm: > 827:2 7 (_ _) > 703:7 6 (_ #) > 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 # =E2=80=A6) > In gnu/services.scm: > 1092:27 2 (_ (#< type: # =E2=80=A6) =E2=80=A6) > 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 > =E2=80=9Cservice=E2=80=9D field of the operating system configuration loo= ked 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 =E2=80=94 and FOLD-SERVICES,= and > many more =E2=80=94 assumes that it is only passed a plain list of servic= es. 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)))) > =E2=80=A6 > (define (assert-type type-check thing message) > (or (false-if-exception (type-check thing)) > (report-error (G_ "type error: =E2=80=A6\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 values.") > > ;; Do things=E2=80=A6 > (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=E2=80= =99d > 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