From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id EIY0DUkDm2ElQgAAgWs5BA (envelope-from ) for ; Mon, 22 Nov 2021 03:41:13 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 8K+7CEkDm2GScQAAbx9fmQ (envelope-from ) for ; Mon, 22 Nov 2021 02:41:13 +0000 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 7D5A033484 for ; Mon, 22 Nov 2021 03:41:11 +0100 (CET) Received: from localhost ([::1]:33378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mozGX-0000JE-Vs for larch@yhetil.org; Sun, 21 Nov 2021 21:41:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mozGQ-0000Hw-Bj for guix-patches@gnu.org; Sun, 21 Nov 2021 21:41:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:34916) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mozGQ-0004uv-2J for guix-patches@gnu.org; Sun, 21 Nov 2021 21:41:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mozGP-0000wT-Tw for guix-patches@gnu.org; Sun, 21 Nov 2021 21:41:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#49671] [PATCH v3] guix: records: Improve error reporting. Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 22 Nov 2021 02:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49671 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49671@debbugs.gnu.org Received: via spool by 49671-submit@debbugs.gnu.org id=B49671.16375488353574 (code B ref 49671); Mon, 22 Nov 2021 02:41:01 +0000 Received: (at 49671) by debbugs.gnu.org; 22 Nov 2021 02:40:35 +0000 Received: from localhost ([127.0.0.1]:46462 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mozFy-0000va-LP for submit@debbugs.gnu.org; Sun, 21 Nov 2021 21:40:35 -0500 Received: from lepiller.eu ([89.234.186.109]:40274) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mozFv-0000vQ-PL for 49671@debbugs.gnu.org; Sun, 21 Nov 2021 21:40:33 -0500 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id 0fb7133e for <49671@debbugs.gnu.org>; Mon, 22 Nov 2021 02:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from :to:subject:message-id:in-reply-to:references:mime-version :content-type; s=dkim; bh=iGD6lU7sHEq64YvvtH8vPHWZeUwfOdHKzjJUAW Ww3aw=; b=Ba28/Xa2ZhHZ0BeOM6F0bIV55BrRVZRct9N8yrQVxdRHHgUuUgkCJZ gbHNIP+0bXWLXUel/TXoIK6lSbctWVKh++32+cezu1RYhqRXjov+8VnNu4xfI2Eq cwc6yx2yuSiS7iJNr3iAA5I5D/mdE4wc9ffQegt1gtUX0VkCd3EPDkkx/3e3y2r5 qwMJj3aOvhUgVSlS2F6yGjMETOmBPC/VZhnUliPcb8BotIlqJ/NnLmMJLw5IHP+1 2qQgA7T8iXF40ozQNCJEmiprAwUX813uYa5Ylbc/iSl8ToAQ9gI630x4XXObNx3O S4HweRrIFKoXcplW0IZzYZP/AzuqGFIw== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id 61c83d1c (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for <49671@debbugs.gnu.org>; Mon, 22 Nov 2021 02:40:29 +0000 (UTC) Date: Mon, 22 Nov 2021 03:40:22 +0100 From: Julien Lepiller Message-ID: <20211122034022.152daf55@tachikoma.lepiller.eu> In-Reply-To: <20211031030635.520a3c6c@tachikoma.lepiller.eu> References: <20210721014047.3878a0c7@tachikoma.lepiller.eu> <20211031030635.520a3c6c@tachikoma.lepiller.eu> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.24; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/O=5syjF3.pIA+c2Heao74c0" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" 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=1637548872; 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:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=A4Mw07zP/Hs1agzw6Afi4whQtFtFVd/f3Q/lA/fv2KA=; b=hcUUl4y1UnHljq183z83POg9adQsGYbgDST0eGNfK+anozGfkrmLaCfjWjqZfyWcF1UcAR rRXg74mkONG2QaoS2+MltA5dDULvb+EQxkRWJ5r3R+e8xDIHXmyb1wsqXtn2jPZLVWaZ+U XluRMIt521RvHfdGrCxzqQFPlog0l3B2f3jZj9AF+s17vBWcMTb3ncOk66Cfk63gd0PqHY yQjFHaZo7+V/F3F/XomlJxSwY5OGqpw9Bjsk4DI3PLxtpR1FCaG0LNFuuQY5yanr3PdRXH 12Mc1/ZGlqjof8ueKan59G7VKXYofH6J5v88K3OY7B82I0rE5igrLY3fzP3t4g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637548872; a=rsa-sha256; cv=none; b=syVALHlHJlOUByW3KuV3+XU1Lyvj6R4ZBvCsfI88o/BEoFdrQg0MULV1xIOH5IpTzVJBvz WlL8N2AWWrncG3E386jnqf5zY3uvlLzuCleiQFlUmzHdgeKNHyeeHKe6ORWukYDjQW2FSG GvUt6MdKggLw8kM8mDhkmW1Br8xLcMWi6+510dzdrR9NnX5mx5tcINvT6Vj16fnuZqRPXc Cp3LBCV4YogkHdbpQq6rcw41okYyEnj99KSKf0+3CALQEYaUrAZdwk4af9gT3V+CMtVyVS 6FGYjGTpVHx+BhWQPdV5seawUEugcsyGQ/G5UwO1fHqES5m/UuBa1CQ6BkbTDQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lepiller.eu header.s=dkim header.b="Ba28/Xa2"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=lepiller.eu (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.78 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lepiller.eu header.s=dkim header.b="Ba28/Xa2"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=lepiller.eu (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 7D5A033484 X-Spam-Score: -1.78 X-Migadu-Scanner: scn0.migadu.com X-TUID: a+HrNJKKdBMY --MP_/O=5syjF3.pIA+c2Heao74c0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Here is another improvement compared to v2. This time there are two patches: the first adds support for &syntax in (guix ui), and will print something like in form: where "in form" is in green. The second patch is very similar to v2, but will now also raise a &syntax condition, so it can be pretty-printed. The previous issue where I printed # is fixed, I simply forgot a syntax->datum. WDYT? --MP_/O=5syjF3.pIA+c2Heao74c0 Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-guix-ui-Print-syntax-errors.patch >From d1d857ea0ca76f1a917382777f57871e50026df3 Mon Sep 17 00:00:00 2001 Message-Id: From: Julien Lepiller Date: Mon, 22 Nov 2021 02:54:06 +0100 Subject: [PATCH 1/2] guix: ui: Print syntax errors. * guix/ui.scm (display-syntax): New procedure. (call-with-error-handling, report-load-error): Print syntax errors. --- guix/ui.scm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/guix/ui.scm b/guix/ui.scm index bd999103ff..79aab2db84 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -69,9 +69,11 @@ (define-module (guix ui) #:use-module (srfi srfi-31) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) + #:use-module (ice-9 exceptions) #:autoload (ice-9 ftw) (scandir) #:use-module (ice-9 match) #:use-module (ice-9 format) + #:use-module (ice-9 pretty-print) #:use-module (ice-9 regex) #:autoload (ice-9 popen) (open-pipe* close-pipe) #:autoload (system repl repl) (start-repl) @@ -315,6 +317,19 @@ (define* (display-hint message #:optional (port (current-error-port))) (texi->plain-text message)) port)) +(define %syntax-color (color BOLD GREEN)) + +(define* (display-syntax form #:optional (port (current-error-port))) + "Display FORM, an sexp, to PORT" + (define colorize + (if (color-output? port) + (lambda (str) + (colorize-string str %syntax-color)) + identity)) + + (display (colorize (G_ "in form: ")) port) + (pretty-print form port)) + (define* (report-unbound-variable-error args #:key frame) "Return the given unbound-variable error, where ARGS is the list of 'throw' arguments." @@ -398,6 +413,9 @@ (define* (report-load-error file args #:optional frame) (formatted-message-arguments obj))) (else (report-error (G_ "exception thrown: ~s~%") obj))) + (when (syntax-error? obj) + (let ((form (or (syntax-error-subform obj) (syntax-error-form obj)))) + (display-syntax form))) (when (fix-hint? obj) (display-hint (condition-fix-hint obj)))) ((key args ...) @@ -801,6 +819,9 @@ (define (call-with-error-handling thunk) (and (error-location? c) (error-location c)) (gettext (formatted-message-string c) %gettext-domain) (formatted-message-arguments c)) + (when (syntax-error? c) + (let ((form (or (syntax-error-subform c) (syntax-error-form c)))) + (display-syntax form))) (when (fix-hint? c) (display-hint (condition-fix-hint c))) (exit 1)) @@ -826,6 +847,9 @@ (define (call-with-error-handling thunk) (report-error (and (error-location? c) (error-location c)) (G_ "~a~%") (gettext (condition-message c) %gettext-domain)) + (when (syntax-error? c) + (let ((form (or (syntax-error-subform c) (syntax-error-form c)))) + (display-syntax form))) (when (fix-hint? c) (display-hint (condition-fix-hint c))) (exit 1))) -- 2.33.1 --MP_/O=5syjF3.pIA+c2Heao74c0 Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=0002-guix-records-Improve-error-reporting.patch =46rom 2eebd1113a40fc6e7018975d3696546de584e4a0 Mon Sep 17 00:00:00 2001 Message-Id: <2eebd1113a40fc6e7018975d3696546de584e4a0.1637548566.git.julien= @lepiller.eu> In-Reply-To: References: From: Julien Lepiller Date: Sun, 31 Oct 2021 02:58:14 +0100 Subject: [PATCH 2/2] guix: records: Improve error reporting. * guix/records.scm (report-invalid-field-specifier): Handle various invalidity causes separately. --- guix/records.scm | 56 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/guix/records.scm b/guix/records.scm index ed94c83dac..eeb5908844 100644 --- a/guix/records.scm +++ b/guix/records.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,= 2021 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2018 Mark H Weaver +;;; Copyright =C2=A9 2021 Julien Lepiller ;;; ;;; This file is part of GNU Guix. ;;; @@ -21,9 +22,13 @@ (define-module (guix records) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-35) + #:use-module (ice-9 exceptions) #:use-module (ice-9 match) #:use-module (ice-9 regex) #:use-module (ice-9 rdelim) + #:use-module (guix diagnostics) + #:use-module (guix ui) #:autoload (system base target) (target-most-positive-fixnum) #:export (define-record-type* this-record @@ -83,10 +88,53 @@ (define-syntax record-error ;; WEIRD may be an identifier, thus lacking source location info,= and ;; BINDINGS is a list, also lacking source location info. Hopefu= lly ;; PARENT-FORM provides source location info. - (apply syntax-violation name "invalid field specifier" - (if parent-form - (list parent-form #'weird) - (list #'weird))))))) + (let* ((weird-properties (source-properties #'weird)) + (parent-properties (and parent-form (syntax-source parent-= form))) + (form parent-form) + (location (source-properties->location + (or (and (not (null? weird-properties)) weird-= properties) + (and (not (null? parent-properties)) paren= t-properties) + '())))) + (syntax-case #'weird () + (() ;the empty list + (raise-exception + (condition + (&message (message (G_ "invalid field specifier."))) + (&syntax (form form) (subform (syntax->datum #'weird))) + (&error-location (location location)) + (&fix-hint (hint (G_ "The format of a field is `(field v= alue)'")))))) + (((field ...) _ ...) ;a list whose first element i= s a list + (raise-exception + (condition + (&message (message (G_ "invalid field name."))) + (&syntax (form form) (subform (map syntax->datum #'(fiel= d ...)))) + (&error-location (location location))))) + ((field) ;a list with one element + (raise-exception + (condition + (&message (message (G_ "missing value in field specifier= ."))) + (&syntax (form form) (subform (syntax->datum #'weird))) + (&error-location (location location)) + (&fix-hint (hint (format #f (G_ "The field is missing a = value: `(~a )'.") + (syntax->datum #'field))))))) + ((field value ...) ;any other list + (raise-exception + (condition + (&message (message (G_ "multiple values in field specifi= er."))) + (&syntax (form form) (subform (syntax->datum #'weird))) + (&error-location (location location)) + (&fix-hint (hint (format #f (G_ "~a values were associat= ed with \ +field `~a'. Perhaps the additional values were intended to be other field= \ +specifiers. This usually indicates missing or misplaced parenthesis.") + (length #'(value ...)) + (syntax->datum #'field))))))) + (field ;not a list + (raise-exception + (condition + (&message (message (G_ "invalid field specifier."))) + (&syntax (form form) (subform (syntax->datum #'weird))) + (&error-location (location location)) + (&fix-hint (hint (G_ "The format of a field is `(field v= alue)'")))))))))))) =20 (define (report-duplicate-field-specifier name ctor) "Report the first duplicate identifier among the bindings in CTOR." --=20 2.33.1 --MP_/O=5syjF3.pIA+c2Heao74c0--