From: Brian Cully via Guix-patches via <guix-patches@gnu.org>
To: 63538@debbugs.gnu.org
Cc: Brian Cully <bjc@spork.org>
Subject: [bug#63538] [PATCH v2 3/3] gnu: services: Error in MODIFY-SERVICES when services don't exist
Date: Fri, 26 May 2023 18:30:17 -0400 [thread overview]
Message-ID: <13ab94bbed475a933d8376ad8fc166c6ad124b67.1685140217.git.bjc@spork.org> (raw)
In-Reply-To: <d289f6bcc270806e2384f2443703ed135dc4c111.1685140217.git.bjc@spork.org>
This patch causes MODIFY-SERVICES to raise an error if a reference is made to
a service which isn't in its service list. This it to help users notice if
they have an invalid rule, which is currently silently ignored.
* gnu/services.scm (%delete-service): new procedure
(%apply-clauses): new syntax rule
(%modify-service): remove syntax rule
---
gnu/services.scm | 47 ++++++++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/gnu/services.scm b/gnu/services.scm
index 31eba9f035..a58cffe536 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -296,20 +296,35 @@ (define (simple-service name target value)
(description "This is a simple service."))))
(service type value)))
-(define-syntax %modify-service
+(define (%delete-service kind services)
+ (let loop ((found #f)
+ (return '())
+ (services services))
+ (match services
+ ('()
+ (if found
+ (values return found)
+ (raise (formatted-message
+ (G_ "modify-services: service '~a' not found in service list")
+ (service-type-name kind)))))
+ ((svc . rest)
+ (if (eq? (service-kind svc) kind)
+ (loop svc return rest)
+ (loop found (cons svc return) rest))))))
+
+(define-syntax %apply-clauses
(syntax-rules (=> delete)
- ((_ svc (delete kind) clauses ...)
- (if (eq? (service-kind svc) kind)
- #f
- (%modify-service svc clauses ...)))
- ((_ service)
- service)
- ((_ svc (kind param => exp ...) clauses ...)
- (if (eq? (service-kind svc) kind)
- (let ((param (service-value svc)))
- (service (service-kind svc)
- (begin exp ...)))
- (%modify-service svc clauses ...)))))
+ ((_ ((delete kind) . rest) services)
+ (%apply-clauses rest (%delete-service kind services)))
+ ((_ ((kind param => exp ...) . rest) services)
+ (call-with-values (lambda () (%delete-service kind services))
+ (lambda (svcs found)
+ (let ((param (service-value found)))
+ (cons (service (service-kind found)
+ (begin exp ...))
+ (%apply-clauses rest svcs))))))
+ ((_ () services)
+ services)))
(define-syntax modify-services
(syntax-rules ()
@@ -345,10 +360,8 @@ (define-syntax modify-services
UDEV-SERVICE-TYPE.
This is a shorthand for (filter-map (lambda (svc) ...) %base-services)."
- ((_ services clauses ...)
- (filter-map (lambda (service)
- (%modify-service service clauses ...))
- services))))
+ ((_ services . clauses)
+ (%apply-clauses clauses services))))
\f
;;;
--
2.40.1
next prev parent reply other threads:[~2023-05-26 22:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-16 15:39 [bug#63538] [PATCH 1/3] tests: Add tests for MODIFY-SERVICES procedure Brian Cully via Guix-patches via
2023-05-26 22:30 ` [bug#63538] [PATCH v2 " Brian Cully via Guix-patches via
2023-05-26 22:30 ` [bug#63538] [PATCH v2 2/3] tests: Check for service existence in MODIFY-SERVICES Brian Cully via Guix-patches via
2023-05-26 22:30 ` Brian Cully via Guix-patches via [this message]
2023-06-02 14:22 ` bug#63538: [PATCH] gnu: services: Error in MODIFY-SERVICES when services don't exist Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=13ab94bbed475a933d8376ad8fc166c6ad124b67.1685140217.git.bjc@spork.org \
--to=guix-patches@gnu.org \
--cc=63538@debbugs.gnu.org \
--cc=bjc@spork.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.