From patchwork Mon Nov 22 02:40:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Julien Lepiller X-Patchwork-Id: 34734 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id A74D627BBE3; Mon, 22 Nov 2021 02:41:10 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 19F5B27BBE1 for ; Mon, 22 Nov 2021 02:41:10 +0000 (GMT) Received: from localhost ([::1]:33378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mozGX-0000JE-9L for patchwork@mira.cbaines.net; Sun, 21 Nov 2021 21:41:09 -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 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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? From 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 © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2018 Mark H Weaver +;;; Copyright © 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. Hopefully ;; 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)) parent-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 value)'")))))) + (((field ...) _ ...) ;a list whose first element is a list + (raise-exception + (condition + (&message (message (G_ "invalid field name."))) + (&syntax (form form) (subform (map syntax->datum #'(field ...)))) + (&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 specifier."))) + (&syntax (form form) (subform (syntax->datum #'weird))) + (&error-location (location location)) + (&fix-hint (hint (format #f (G_ "~a values were associated 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 value)'")))))))))))) (define (report-duplicate-field-specifier name ctor) "Report the first duplicate identifier among the bindings in CTOR." -- 2.33.1