From 4cde5555682ca6a3c78cb274cc308087e51ea0e9 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Wed, 21 Jul 2021 01:30:04 +0200 Subject: [PATCH] guix: records: Improve error reporting. * guix/records.scm (report-invalid-field-specifier): Handle various invalidity causes separately. --- guix/records.scm | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/guix/records.scm b/guix/records.scm index 3d54a51956..3c3dd478a5 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 Ludovic Courtès ;;; Copyright © 2018 Mark H Weaver +;;; Copyright © 2021 Julien Lepiller ;;; ;;; This file is part of GNU Guix. ;;; @@ -83,10 +84,40 @@ error-reporting purposes." ;; 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 + (syntax-case #'weird () + (() ;the empty list + (apply syntax-violation name + "invalid field specifier. The format of a field is `(field value)'" (list parent-form #'weird) - (list #'weird))))))) + (list #'weird))) + (((field ...) _ ...) ;a list whose first element is a list + (apply syntax-violation name + (format #f "invalid field specifier. ~a is not a valid field name." + (map syntax->datum #'(field ...))) + (list parent-form #'weird) + (list #'weird))) + ((field) ;a list with one element + (apply syntax-violation name + (format #f "Value missing in field specifier. The format of \ +a field is `(~a value)'." + (syntax->datum #'field)) + (list parent-form #'weird) + (list #'weird))) + ((field value ...) ;any other list + (apply syntax-violation name + (format #f "multiple values in field specifier. Got ~a values \ +associated with key ~a. Values are:~%~{~a~%~}" + (length #'(value ...)) (syntax->datum #'field) + (map syntax->datum #'(value ...))) + (list parent-form #'weird) + (list #'weird))) + (field ;not a list + (apply syntax-violation name + (format #f "invalid field specifier. The format of a field \ +is `(~a value)'" + (syntax->datum #'field)) + (list parent-form #'weird) + (list #'weird)))))))) (define (report-duplicate-field-specifier name ctor) "Report the first duplicate identifier among the bindings in CTOR." -- 2.32.0