From fb7e6ccba7cc243cd96cdc3fde3daa9a5f08e531 Mon Sep 17 00:00:00 2001
From: Ludovic Courtès <ludo@gnu.org>
Date: Sat, 18 Jun 2022 22:37:20 +0200
Subject: services: configuration: Report the location of field type errors.

Previously field type errors would be reported in a non-standard way,
and without any source location information.  This fixes it.

* gnu/services/configuration.scm (configuration-field-error): Add a
'loc' parameter and honor it.  Use 'formatted-message' instead of plain
'format'.
(define-configuration-helper)[field-sanitizer]: New procedure.
Use it.  Use STEM as the identifier of the syntactic constructor of the
record type.  Add a 'sanitize' property to each field.  Remove now
useless STEM macro that would call 'validate-configuration'.
* gnu/services/mail.scm (serialize-listener-configuration): Adjust to
new 'configuration-field-error' prototype.
* tests/services/configuration.scm ("wrong type for a field"): New test.
* po/guix/POTFILES.in: Add gnu/services/configuration.scm.
---
 tests/services/configuration.scm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

(limited to 'tests/services/configuration.scm')

diff --git a/tests/services/configuration.scm b/tests/services/configuration.scm
index 334a1e409b..6268525317 100644
--- a/tests/services/configuration.scm
+++ b/tests/services/configuration.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
+;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -19,6 +20,7 @@
 
 (define-module (tests services configuration)
   #:use-module (gnu services configuration)
+  #:use-module (guix diagnostics)
   #:use-module (guix gexp)
   #:use-module (srfi srfi-34)
   #:use-module (srfi srfi-64))
@@ -43,6 +45,17 @@ (define-configuration port-configuration
   80
   (port-configuration-port (port-configuration)))
 
+(test-equal "wrong type for a field"
+  '("configuration.scm" 57 11)                    ;error location
+  (guard (c ((configuration-error? c)
+             (let ((loc (error-location c)))
+               (list (basename (location-file loc))
+                     (location-line loc)
+                     (location-column loc)))))
+    (port-configuration
+     ;; This is line 56; the test relies on line/column numbers!
+     (port "This is not a number!"))))
+
 (define-configuration port-configuration-cs
   (port (number 80) "The port number." empty-serializer))
 
-- 
cgit v1.2.3