From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.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 GCSNGJHgCmLHfgEAgWs5BA (envelope-from ) for ; Tue, 15 Feb 2022 00:06:57 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id ECAPFpHgCmJKuwAA9RJhRA (envelope-from ) for ; Tue, 15 Feb 2022 00:06:57 +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 1F59BCFF3 for ; Tue, 15 Feb 2022 00:06:57 +0100 (CET) Received: from localhost ([::1]:59928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJkQq-0006Uk-73 for larch@yhetil.org; Mon, 14 Feb 2022 18:06:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJkMS-0003a2-7F for guix-devel@gnu.org; Mon, 14 Feb 2022 18:02:24 -0500 Received: from sender4-of-o51.zoho.com ([136.143.188.51]:21151) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJkMQ-00052t-0m for guix-devel@gnu.org; Mon, 14 Feb 2022 18:02:23 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1644879737; cv=none; d=zohomail.com; s=zohoarc; b=lX2tzy3ZfmGXHyfGoX1qmVcoEBcepfVIkoOTAuB5RgIm3Ku+w6VsgFAhb1CwG9O+sfKMrfDY1ETr0g7y/Ndp/8zMHjnP7FscH2IN+xWazxFmU0wiElGdMapa6/sOuakbV2dqZNhoDwqp6uT1IFhn3xQMLzu8a8RjIGhBdthYzgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644879737; h=Content-Type:Content-Transfer-Encoding:Date:From:MIME-Version:Message-ID:Subject:To; bh=MqRanxhBzuuH3WEhjAg/s559ssAdFR4moRtTOC6pR4c=; b=bawMI4uVAn0Ur5ltcUKj2YIOuDefSoz8CspkljXvyckYPdc25kXsoG2U6H7a7aRjqTTsLQWt7p5//gcRJlobCRJZUUzHHXLbOPSknq0PLpTe2CNgcyBYu93D6ibXWHjMD3uqNhMbrPau8XBeUw+HKkE216rWAqAXWTtAApmD4DI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1644879737; s=zoho; d=elephly.net; i=rekado@elephly.net; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=MqRanxhBzuuH3WEhjAg/s559ssAdFR4moRtTOC6pR4c=; b=Bhcn35Nj5S5Ak59gNX2Yy3txxwEo5z/VR72RkYqjM3fzcU2wu1OOOQ2aY5jMCac1 3mjLqGTPi6dq7LZoaBkrGvVCON4W7JakqWPuZluqIIFq3810ycsFE7xeJsveN6YqGez eWOGdottXxKm7Ft97zyk4NIOry/LpN9DJFBuisjQ= Received: from localhost (p54ad4f31.dip0.t-ipconnect.de [84.173.79.49]) by mx.zohomail.com with SMTPS id 1644879736570502.30261617664803; Mon, 14 Feb 2022 15:02:16 -0800 (PST) User-agent: mu4e 1.6.10; emacs 27.2 From: Ricardo Wurmus To: guix-devel@gnu.org Subject: better error messages through assertions Date: Mon, 14 Feb 2022 23:32:22 +0100 X-URL: https://elephly.net X-PGP-Key: https://elephly.net/rekado.pubkey X-PGP-Fingerprint: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC Message-ID: <87ilthoxvu.fsf@elephly.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Received-SPF: pass client-ip=136.143.188.51; envelope-from=rekado@elephly.net; helo=sender4-of-o51.zoho.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , 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=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644880017; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=MqRanxhBzuuH3WEhjAg/s559ssAdFR4moRtTOC6pR4c=; b=a5AgfGZNtK4gyB8dzORTqcZdD3ifZS5b3L4GKnHKLpsEdnZBLT6R3NFNmu11wlsnhRvKYw vfll0ZiayKglQwEAN2nGPJeacDRkQ/KcvNWYI2Nz8y40MZtyYukj3vJcJQ7clUXB8v4VGd TUikGT6tu+D6ujxARqENIJPWQ3zf0pHsqHbnyLobURzImn7+ZL9TUJkHrdX8v3env2NRcC VghJVMp7aQIDb+6cmzja7X8ynn9zsjCK4Trscbb9jfho9IOwgKh0oYMn1eeTHJwHr1Z0Jc shjWYUDmtl5RNX+z84ZL4oKTrKZBET57GcsQWg5lDufRgGG9Yb5Q/8qvmSEsuA== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1644880017; a=rsa-sha256; cv=pass; b=paPWJccY1Ljx+2h/YB2LQ5tGaroK3NjzS/NA5Wusk+WW2Zzrb8e3S5yqCI4rDs2TdzwK/W pTtBmA5aqJG1JpenO7j4D55HsvY+RylE8ffJ5KkDRh+vuvMiVqkPNGCX2u/wgxFLp43ag2 3ng0nhOeQpJBfCJILaSyUzO2HvCRaNPI93xgkqDV+ZhE3DH4W19Qh8XLBr2atnmXwDCt1f 01vg9JcmEsvVcg09FQGWpM1FBddLuoZ4FpW7oclkhQk8CrWtRTk0Nn157YyX8iPte2lIx+ FjWXaNqREBVFFxzt9942UYKym+GzWr0tZZ/+s5PlL1+H48y3LJNvut3Q10+8Dg== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=elephly.net header.s=zoho header.b=Bhcn35Nj; arc=pass ("zohomail.com:s=zohoarc:i=1"); dmarc=none; 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: -10.33 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=elephly.net header.s=zoho header.b=Bhcn35Nj; arc=pass ("zohomail.com:s=zohoarc:i=1"); dmarc=none; 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: 1F59BCFF3 X-Spam-Score: -10.33 X-Migadu-Scanner: scn0.migadu.com X-TUID: 8QkrCBnhoQE7 Hi Guix, today on IRC someone reported an ugly error message when reconfiguring their system: --8<---------------cut here---------------start------------->8--- 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 st= ruct): --8<---------------cut here---------------end--------------->8--- As you can probably tell easily by looking at this message, the =E2=80=9Cservice=E2=80=9D field of the operating system configuration looke= d 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, a= nd many more =E2=80=94 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)))) =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. --=20 Ricardo