Some simplification of process error message contracts.

(manually adapted)

(cherry picked from commit 4bd42606bc)
This commit is contained in:
Eli Barzilay 2012-07-20 12:57:28 -04:00 committed by Ryan Culpepper
parent ec319cb467
commit 298dd3e62c

View File

@ -44,15 +44,13 @@
(define (path-or-ok-string? s) (define (path-or-ok-string? s)
;; use `path-string?' t check for nul characters in a string, ;; use `path-string?' t check for nul characters in a string,
;; but allow the empty string (which is not an ok path), too: ;; but allow the empty string (which is not an ok path), too:
(or (path-string? s) (or (path-string? s) (equal? "" s)))
(equal? "" s)))
(define (string-no-nuls? s) (define (string-no-nuls? s)
(and (string? s) (path-or-ok-string? s))) (and (string? s) (path-or-ok-string? s)))
(define (bytes-no-nuls? s) (define (bytes-no-nuls? s)
(and (bytes? s) (and (bytes? s) (not (regexp-match? #rx#"\0" s))))
(not (regexp-match? #rx#"\0" s))))
(define (check-args who args) (define (check-args who args)
(cond (cond
@ -76,23 +74,13 @@
(caddr args)))] (caddr args)))]
[else [else
(for ([s (in-list args)]) (for ([s (in-list args)])
(unless (or (path-or-ok-string? s) (unless (or (path-or-ok-string? s) (bytes-no-nuls? s))
(bytes-no-nuls? s)) (raise-argument-error who "(or/c path-string? bytes-no-nuls?)" s)))])
(raise-argument-error
who
(string-append "(or/c path-string?\n"
" (and/c bytes? bytes-no-nuls?))")
s)))])
args) args)
(define (check-command who str) (define (check-command who str)
(unless (or (string-no-nuls? str) (unless (or (string-no-nuls? str) (bytes-no-nuls? str))
(bytes-no-nuls? str)) (raise-argument-error who "(or/c string-no-nuls? bytes-no-nuls?)" str)))
(raise-argument-error
who
(string-append "(or/c (and/c string? string-no-nuls?)\n"
" (and/c bytes? bytes-no-nuls?))")
str)))
;; Old-style functions: ---------------------------------------- ;; Old-style functions: ----------------------------------------