diff --git a/racket/src/io/demo.rkt b/racket/src/io/demo.rkt index dc88c1dad7..a0e5e5393f 100644 --- a/racket/src/io/demo.rkt +++ b/racket/src/io/demo.rkt @@ -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 diff --git a/racket/src/io/format/printf.rkt b/racket/src/io/format/printf.rkt index 45e71cc0cc..533e73e1d5 100644 --- a/racket/src/io/format/printf.rkt +++ b/racket/src/io/format/printf.rkt @@ -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)))))))) + ""))