mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-23 21:17:11 -05:00
Make `define-record-type*' error messages more informative.
* guix/utils.scm (define-record-type*): In case of missing or extra field initializers, raise a descriptive `syntax-error'.
This commit is contained in:
parent
888f72e97f
commit
8ef3401f65
1 changed files with 18 additions and 5 deletions
|
@ -30,6 +30,7 @@ (define-module (guix utils)
|
|||
#:autoload (ice-9 rdelim) (read-line)
|
||||
#:use-module (ice-9 regex)
|
||||
#:use-module (ice-9 match)
|
||||
#:use-module (ice-9 format)
|
||||
#:autoload (system foreign) (pointer->procedure)
|
||||
#:export (bytevector-quintet-length
|
||||
bytevector->base32-string
|
||||
|
@ -493,11 +494,23 @@ (define (field-value f)
|
|||
((_ v) v)
|
||||
(#f (car (assoc-ref dflt f)))))
|
||||
|
||||
(if (lset= eq? (append fields (map car dflt))
|
||||
'expected)
|
||||
#`(ctor #,@(map field-value 'expected))
|
||||
(error "missing or extraneous field initializers"
|
||||
(lset-difference eq? fields 'expected))))))))))
|
||||
(let-syntax ((error*
|
||||
(syntax-rules ()
|
||||
((_ fmt args (... ...))
|
||||
(syntax-violation 'name
|
||||
(format #f fmt args
|
||||
(... ...))
|
||||
s)))))
|
||||
(let ((fields (append fields (map car dflt))))
|
||||
(cond ((lset= eq? fields 'expected)
|
||||
#`(ctor #,@(map field-value 'expected)))
|
||||
((pair? (lset-difference eq? fields 'expected))
|
||||
(error* "extraneous field initializers ~a"
|
||||
(lset-difference eq? fields 'expected)))
|
||||
(else
|
||||
(error* "missing field initializers ~a"
|
||||
(lset-difference eq? 'expected
|
||||
fields)))))))))))))
|
||||
|
||||
(define (field-default-value s)
|
||||
(syntax-case s (default)
|
||||
|
|
Loading…
Reference in a new issue