From fb7e6ccba7cc243cd96cdc3fde3daa9a5f08e531 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès 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. --- gnu/services/mail.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnu/services/mail.scm') diff --git a/gnu/services/mail.scm b/gnu/services/mail.scm index d99743ac31..c2fd4d8670 100644 --- a/gnu/services/mail.scm +++ b/gnu/services/mail.scm @@ -285,7 +285,7 @@ the section name.") (serialize-fifo-listener-configuration field-name val)) ((inet-listener-configuration? val) (serialize-inet-listener-configuration field-name val)) - (else (configuration-field-error field-name val)))) + (else (configuration-field-error #f field-name val)))) (define (listener-configuration-list? val) (and (list? val) (and-map listener-configuration? val))) (define (serialize-listener-configuration-list field-name val) -- cgit 1.4.1 From 6505f727e1824391b888dd0c2c60cf64ec66955a Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 18 Jun 2022 22:59:22 +0200 Subject: services: configuration: Remove 'validate-configuration'. Now that configuration records use the 'sanitize' property for each field, 'validate-configuration' has become useless because it's impossible to construct an invalid configuration record. * gnu/services/configuration.scm (validate-configuration): Remove. * gnu/services/mail.scm (dovecot-service): Remove call. * gnu/services/vpn.scm (openvpn-client-service) (openvpn-server-service): Likewise. * doc/guix.texi (Complex Configurations): Remove documentation. --- doc/guix.texi | 6 ------ gnu/services/configuration.scm | 9 --------- gnu/services/mail.scm | 4 ---- gnu/services/vpn.scm | 2 -- 4 files changed, 21 deletions(-) (limited to 'gnu/services/mail.scm') diff --git a/doc/guix.texi b/doc/guix.texi index f3b026333e..794907ce3a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -38917,12 +38917,6 @@ Return a G-expression that contains the values corresponding to the disk by using something like @code{mixed-text-file}. @end deffn -@deffn {Scheme Procedure} validate-configuration @var{configuration} -@var{fields} -Type-check @var{fields}, a list of field names of @var{configuration}, a -configuration record created by @code{define-configuration}. -@end deffn - @deffn {Scheme Procedure} empty-serializer @var{field-name} @var{value} A serializer that just returns an empty string. The @code{serialize-package} procedure is an alias for this. diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index c39ea5a02a..e3c101d042 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -57,7 +57,6 @@ serialize-configuration define-maybe define-maybe/no-serialization - validate-configuration generate-documentation configuration->documentation empty-serializer @@ -125,14 +124,6 @@ does not have a default value" field kind))) ((configuration-field-getter field) config))) fields))) -(define (validate-configuration config fields) - (for-each (lambda (field) - (let ((val ((configuration-field-getter field) config))) - (unless ((configuration-field-predicate field) val) - (configuration-field-error - (configuration-field-name field) val)))) - fields)) - (define-syntax-rule (id ctx parts ...) "Assemble PARTS into a raw (unhygienic) identifier." (datum->syntax ctx (symbol-append (syntax->datum parts) ...))) diff --git a/gnu/services/mail.scm b/gnu/services/mail.scm index c2fd4d8670..10e6523861 100644 --- a/gnu/services/mail.scm +++ b/gnu/services/mail.scm @@ -1610,10 +1610,6 @@ POP3, IMAP, and LMTP. @var{config} should be a configuration object created by @code{dovecot-configuration}. @var{config} may also be created by @code{opaque-dovecot-configuration}, which allows specification of the @code{dovecot.conf} as a string." - (validate-configuration config - (if (opaque-dovecot-configuration? config) - opaque-dovecot-configuration-fields - dovecot-configuration-fields)) (service dovecot-service-type config)) ;; A little helper to make it easier to document all those fields. diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm index 6a289d357a..82ff05b351 100644 --- a/gnu/services/vpn.scm +++ b/gnu/services/vpn.scm @@ -540,11 +540,9 @@ is truncated and rewritten every minute.") to an existing @acronym{VPN, virtual private network}."))) (define* (openvpn-client-service #:key (config (openvpn-client-configuration))) - (validate-configuration config openvpn-client-configuration-fields) (service openvpn-client-service-type config)) (define* (openvpn-server-service #:key (config (openvpn-server-configuration))) - (validate-configuration config openvpn-server-configuration-fields) (service openvpn-server-service-type config)) (define (generate-openvpn-server-documentation) -- cgit 1.4.1