* [bug#63538] [PATCH 2/3] tests: Check for service existence in MODIFY-SERVICES
[not found] <999ea3ff3ea32e4e1bb8b7b8abd4e0e29d1f2395.1684251702.git.bjc@spork.org>
@ 2023-05-16 15:41 ` Brian Cully via Guix-patches via
2023-05-16 15:41 ` [bug#63538] [PATCH 3/3] gnu: services: Error in MODIFY-SERVICES when services don't exist Brian Cully via Guix-patches via
1 sibling, 0 replies; 3+ messages in thread
From: Brian Cully via Guix-patches via @ 2023-05-16 15:41 UTC (permalink / raw)
To: 63538; +Cc: Brian Cully
* tests/services.scm ("modify-services: delete non-existing service")
("modify-services: change value for non-existing service"): New tests.
---
tests/services.scm | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/tests/services.scm b/tests/services.scm
index 435f39e59b..5a9cd47489 100644
--- a/tests/services.scm
+++ b/tests/services.scm
@@ -319,6 +319,21 @@ (define-module (test-services)
(delete t2)))
<)))
+(test-error "modify-services: delete non-existing service"
+ #t
+ (let* ((t1 (service-type (name 't1)
+ (extensions '())
+ (description "")))
+ (t2 (service-type (name 't2)
+ (extensions '())
+ (description "")))
+ (t3 (service-type (name 't2)
+ (extensions '())
+ (description "")))
+ (services (list (service t1 1) (service t2 2))))
+ (modify-services services
+ (delete t3))))
+
(test-equal "modify-services: change value"
'(1 2 33)
(let* ((t1 (service-type (name 't1)
@@ -336,4 +351,20 @@ (define-module (test-services)
(t3 value => 33)))
<)))
+(test-error "modify-services: change value for non-existing service"
+ #t
+ (let* ((t1 (service-type (name 't1)
+ (extensions '())
+ (description "")))
+ (t2 (service-type (name 't2)
+ (extensions '())
+ (description "")))
+ (t3 (service-type (name 't3)
+ (extensions '())
+ (description "")))
+ (services (list (service t1 1) (service t3 3))))
+ (map service-value
+ (modify-services services
+ (t2 value => 22)))))
+
(test-end)
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [bug#63538] [PATCH 3/3] gnu: services: Error in MODIFY-SERVICES when services don't exist
[not found] <999ea3ff3ea32e4e1bb8b7b8abd4e0e29d1f2395.1684251702.git.bjc@spork.org>
2023-05-16 15:41 ` [bug#63538] [PATCH 2/3] tests: Check for service existence in MODIFY-SERVICES Brian Cully via Guix-patches via
@ 2023-05-16 15:41 ` Brian Cully via Guix-patches via
2023-05-26 22:27 ` [bug#63538] [PATCH] " Brian Cully via Guix-patches via
1 sibling, 1 reply; 3+ messages in thread
From: Brian Cully via Guix-patches via @ 2023-05-16 15:41 UTC (permalink / raw)
To: 63538; +Cc: Brian Cully
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 d6c7ad0553..988325b253 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 ...))
+ 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [bug#63538] [PATCH] gnu: services: Error in MODIFY-SERVICES when services don't exist
2023-05-16 15:41 ` [bug#63538] [PATCH 3/3] gnu: services: Error in MODIFY-SERVICES when services don't exist Brian Cully via Guix-patches via
@ 2023-05-26 22:27 ` Brian Cully via Guix-patches via
0 siblings, 0 replies; 3+ messages in thread
From: Brian Cully via Guix-patches via @ 2023-05-26 22:27 UTC (permalink / raw)
To: 63538
The previous patch is incorrect, because it didn't continue recursing
after a modify rule. The next set fixes that, and adds a test for it.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-26 22:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <999ea3ff3ea32e4e1bb8b7b8abd4e0e29d1f2395.1684251702.git.bjc@spork.org>
2023-05-16 15:41 ` [bug#63538] [PATCH 2/3] tests: Check for service existence in MODIFY-SERVICES Brian Cully via Guix-patches via
2023-05-16 15:41 ` [bug#63538] [PATCH 3/3] gnu: services: Error in MODIFY-SERVICES when services don't exist Brian Cully via Guix-patches via
2023-05-26 22:27 ` [bug#63538] [PATCH] " Brian Cully via Guix-patches via
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.