From 72724673c80149228bc1028849c00985fce92f93 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Sat, 20 May 2023 23:05:06 +1000 Subject: build: utils: Raise error in modify-phases upon missing key. * guix/build/utils.scm (alist-cons-before) (alist-cons-after): Error with a match failure if the reference is not found, instead of appending to the alist. * tests/build-utils.scm: Update tests to match the new behavior. Signed-off-by: Maxim Cournoyer Change-Id: I3044b101bd06231d5cd55a544ac1009e6ce6f9a0 --- guix/build/utils.scm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'guix/build/utils.scm') diff --git a/guix/build/utils.scm b/guix/build/utils.scm index 2352a627e9..8e630ad586 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -9,6 +9,7 @@ ;;; Copyright © 2020, 2021 Maxim Cournoyer ;;; Copyright © 2021, 2022 Maxime Devos ;;; Copyright © 2021 Brendan Tildesley +;;; Copyright © 2023 Carlo Zancanaro ;;; ;;; This file is part of GNU Guix. ;;; @@ -729,18 +730,22 @@ (define (every* pred lst) (define* (alist-cons-before reference key value alist #:optional (key=? equal?)) "Insert the KEY/VALUE pair before the first occurrence of a pair whose key -is REFERENCE in ALIST. Use KEY=? to compare keys." +is REFERENCE in ALIST. Use KEY=? to compare keys. An error is raised when no +such pair exists." (let-values (((before after) (break (match-lambda ((k . _) (key=? k reference))) alist))) - (append before (alist-cons key value after)))) + (match after + ((_ _ ...) + (append before (alist-cons key value after)))))) (define* (alist-cons-after reference key value alist #:optional (key=? equal?)) "Insert the KEY/VALUE pair after the first occurrence of a pair whose key -is REFERENCE in ALIST. Use KEY=? to compare keys." +is REFERENCE in ALIST. Use KEY=? to compare keys. An error is raised when +no such pair exists." (let-values (((before after) (break (match-lambda ((k . _) @@ -748,9 +753,7 @@ (define* (alist-cons-after reference key value alist alist))) (match after ((reference after ...) - (append before (cons* reference `(,key . ,value) after))) - (() - (append before `((,key . ,value))))))) + (append before (cons* reference `(,key . ,value) after)))))) (define* (alist-replace key value alist #:optional (key=? equal?)) "Replace the first pair in ALIST whose car is KEY with the KEY/VALUE pair. -- cgit v1.2.3