io: format error message fixes.

This commit is contained in:
Sam Tobin-Hochstadt 2017-02-24 10:31:25 -05:00 committed by Sam Tobin-Hochstadt
parent 0af11de62b
commit 7f44aaf2bf
2 changed files with 26 additions and 4 deletions

View File

@ -153,12 +153,23 @@
(with-handlers ([exn:fail? exn-message])
(error 'no "hi ~s" 10)))
(test "error: format string requires 1 arguments, given 3"
(test "error: format string requires 1 arguments, given 3; arguments were: 1 2 3"
(with-handlers ([exn:fail? exn-message])
(error 'no "hi ~s" 1 2 3)))
(test "error: format string requires 2 arguments, given 1"
(test "error: format string requires 2 arguments, given 1; arguments were: 8"
(with-handlers ([exn:fail? exn-message])
(error 'no "hi ~s ~s" 8)))
(test "error: format string requires 2 arguments, given 100"
(with-handlers ([exn:fail? exn-message])
(apply error 'no "hi ~s ~s" (for/list ([i 100]) i))))
(test "error: format string requires 2 arguments, given 51"
(with-handlers ([exn:fail? exn-message])
(apply error 'no "hi ~s ~s" (for/list ([i 51]) i))))
(test (apply string-append
"error: format string requires 2 arguments, given 50; arguments were:"
(for/list ([i 50]) (string-append " " (number->string i))))
(with-handlers ([exn:fail? exn-message])
(apply error 'no "hi ~s ~s" (for/list ([i 50]) i))))
(define infinite-ones
(make-input-port 'ones

View File

@ -195,5 +195,16 @@
(define (value->string v)
((error-value->string-handler) v (error-print-width)))
(define (arguments->string args)
"")
(define (arguments->string fmt+args)
(define args (cdr fmt+args))
(if (or (null? args) (<= (length args) 50))
(parameterize ([error-print-width
(max 2 (round (/ (error-print-width) (length args))))])
(apply string-append
"; "
"arguments were: "
(let loop ([ss (map value->string args)])
(if (or (null? ss) (null? (cdr ss)))
ss
(cons (car ss) (cons " " (loop (cdr ss))))))))
""))