From 2eebd1113a40fc6e7018975d3696546de584e4a0 Mon Sep 17 00:00:00 2001
Message-Id: <2eebd1113a40fc6e7018975d3696546de584e4a0.1637548566.git.julien@lepiller.eu>
In-Reply-To: <d1d857ea0ca76f1a917382777f57871e50026df3.1637548566.git.julien@lepiller.eu>
References: <d1d857ea0ca76f1a917382777f57871e50026df3.1637548566.git.julien@lepiller.eu>
* guix/records.scm (report-invalid-field-specifier): Handle various
invalidity causes separately.
guix/records.scm | 56 ++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 52 insertions(+), 4 deletions(-)
Toggle diff (86 lines)
diff --git a/guix/records.scm b/guix/records.scm
index ed94c83dac..eeb5908844 100644
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
+;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
;;; 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)
#:autoload (system base target) (target-most-positive-fixnum)
#:export (define-record-type*
@@ -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"
- (list parent-form #'weird)
+ (let* ((weird-properties (source-properties #'weird))
+ (parent-properties (and parent-form (syntax-source parent-form)))
+ (location (source-properties->location
+ (or (and (not (null? weird-properties)) weird-properties)
+ (and (not (null? parent-properties)) parent-properties)
+ (syntax-case #'weird ()
+ (&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
+ (&message (message (G_ "invalid field name.")))
+ (&syntax (form form) (subform (map syntax->datum #'(field ...))))
+ (&error-location (location location)))))
+ ((field) ;a list with one element
+ (&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 <value>)'.")
+ (syntax->datum #'field)))))))
+ ((field value ...) ;any other list
+ (&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.")
+ (syntax->datum #'field)))))))
+ (&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."