mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-29 19:30:36 +02:00
Fix error messages containing format strings
The builtin primitive procedure `error` takes an optional message and a list of arguments to include into the error message. These args are formatted with `~S` and appended to the error message, so that an example call of `(error "Wrong argument: " 42)` results in the output "Wrong argument: 42" If format strings occur in the message itself, however, they are escaped. Thus a call like `(error "Wrong argument: ~a" 42)` is rendered as "Wrong argument: ~a 42" Some callers did not take this behavior into account, leading to confusing error messages. Changing the behavior of `error` to be both backwards-compatible and accept also format strings inside messages is not straightforward, because it would have to handle escaped `~` characters as well. Therefore, fix `error` call sites using format strings to use `format` before calling out to `error`. The following files are affected: * module/ice-9/format.scm (format) * module/ice-9/r6rs-libraries.scm (resolve-r6rs-interface) * module/oop/goops.scm (make) * module/srfi/srfi-37.scm (Comment at the beginning of file) * module/system/base/compile.scm (call-once) * module/system/repl/command.scm (break, tracepoint) * module/system/repl/common.scm (repl-default-options) * module/system/vm/traps.scm (arg-check, trap-at-source-location) There are a couple of further call sites that were left unchanged, either because they are using their own `error` procedure: * module/ice-9/read.scm * module/ice-9/command-line.scm or are not referenced from other modules: * module/system/base/lalr.upstream.scm: * module/sxml/upstream/assert.scm: * module/sxml/sxml-match.ss: Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
57a889b728
commit
80d4055e42
8 changed files with 30 additions and 16 deletions
|
@ -49,7 +49,8 @@
|
|||
((boolean? destination) (current-output-port)) ; boolean but not false
|
||||
((output-port? destination) destination)
|
||||
(else
|
||||
(error "format: bad destination `~a'" destination)))))
|
||||
(error
|
||||
(simple-format #f "format: bad destination `~a'" destination))))))
|
||||
|
||||
(define %output-col (or (port-column port) 0))
|
||||
(define %flush-output? #f)
|
||||
|
|
|
@ -115,8 +115,10 @@
|
|||
(for-each (lambda (sym)
|
||||
(module-add! iface sym
|
||||
(or (module-variable mod sym)
|
||||
(error "no binding `~A' in module ~A"
|
||||
sym mod)))
|
||||
(error (format
|
||||
#f
|
||||
"no binding `~A' in module ~A"
|
||||
sym mod))))
|
||||
(when (hashq-ref (module-replacements mod) sym)
|
||||
(hashq-set! (module-replacements iface) sym #t)))
|
||||
(syntax->datum #'(identifier ...)))
|
||||
|
@ -131,7 +133,7 @@
|
|||
mod)
|
||||
(for-each (lambda (sym)
|
||||
(unless (module-local-variable iface sym)
|
||||
(error "no binding `~A' in module ~A" sym mod))
|
||||
(error (format #f "no binding `~A' in module ~A" sym mod)))
|
||||
(module-remove! iface sym))
|
||||
(syntax->datum #'(identifier ...)))
|
||||
iface))
|
||||
|
@ -167,7 +169,11 @@
|
|||
(replace? (vector-ref v 1))
|
||||
(var (vector-ref v 2)))
|
||||
(when (module-local-variable iface to)
|
||||
(error "duplicate binding for `~A' in module ~A" to mod))
|
||||
(error (format
|
||||
#f
|
||||
"duplicate binding for `~A' in module ~A"
|
||||
to
|
||||
mod)))
|
||||
(module-add! iface to var)
|
||||
(when replace?
|
||||
(hashq-set! replacements to #t))))
|
||||
|
@ -178,7 +184,8 @@
|
|||
(to (cdar in))
|
||||
(var (module-variable mod from))
|
||||
(replace? (hashq-ref replacements from)))
|
||||
(unless var (error "no binding `~A' in module ~A" from mod))
|
||||
(unless var (error
|
||||
(format #f "no binding `~A' in module ~A" from mod)))
|
||||
(module-remove! iface from)
|
||||
(hashq-remove! replacements from)
|
||||
(lp (cdr in) (cons (vector to replace? var) out))))))))
|
||||
|
|
|
@ -542,7 +542,7 @@ followed by its associated value. If @var{l} does not hold a value for
|
|||
;; Boot definition.
|
||||
(define (make class . args)
|
||||
(unless (memq <slot> (class-precedence-list class))
|
||||
(error "Unsupported class: ~S" class))
|
||||
(error (format #f "Unsupported class: ~S" class)))
|
||||
(make-slot class args))
|
||||
|
||||
;; Boot definition.
|
||||
|
|
|
@ -31,9 +31,9 @@
|
|||
;; (display-and-exit-proc "Foo version 42.0\n"))
|
||||
;; (option '(#\h "help") #f #f
|
||||
;; (display-and-exit-proc
|
||||
;; "Usage: foo scheme-file ..."))))
|
||||
;; "Usage: foo scheme-file ...\n"))))
|
||||
;; (lambda (opt name arg)
|
||||
;; (error "Unrecognized option `~A'" name))
|
||||
;; (error (format #f "Unrecognized option `~A'" name)))
|
||||
;; (lambda (op) (load op) (values)))
|
||||
;;
|
||||
;;; Code:
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
(dynamic-wind
|
||||
(lambda ()
|
||||
(when entered
|
||||
(error "thunk may only be entered once: ~a" thunk))
|
||||
(error (format #f "thunk may only be entered once: ~a" thunk)))
|
||||
(set! entered #t))
|
||||
thunk
|
||||
(lambda () #t))))
|
||||
|
|
|
@ -672,7 +672,7 @@ Break on calls to PROCEDURE.
|
|||
Starts a recursive prompt when PROCEDURE is called."
|
||||
(let ((proc (repl-eval repl (repl-parse repl form))))
|
||||
(if (not (procedure? proc))
|
||||
(error "Not a procedure: ~a" proc)
|
||||
(error (format #f "Not a procedure: ~a" proc))
|
||||
(let ((idx (add-trap-at-procedure-call! proc)))
|
||||
(format #t "Trap ~a: ~a.~%" idx (trap-name idx))))))
|
||||
|
||||
|
@ -783,7 +783,7 @@ A tracepoint will print out the procedure and its arguments, when it is
|
|||
called, and its return value(s) when it returns."
|
||||
(let ((proc (repl-eval repl (repl-parse repl form))))
|
||||
(if (not (procedure? proc))
|
||||
(error "Not a procedure: ~a" proc)
|
||||
(error (format #f "Not a procedure: ~a" proc))
|
||||
(let ((idx (add-trace-at-procedure-call! proc)))
|
||||
(format #t "Trap ~a: ~a.~%" idx (trap-name idx))))))
|
||||
|
||||
|
|
|
@ -142,7 +142,12 @@ See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
|
|||
(lambda (x)
|
||||
(if (memq x vals)
|
||||
x
|
||||
(error "Bad on-error value ~a; expected one of ~a" x vals))))))))
|
||||
(error
|
||||
(format
|
||||
#f
|
||||
"Bad on-error value ~a; expected one of ~a"
|
||||
x
|
||||
vals)))))))))
|
||||
|
||||
(define %make-repl make-repl)
|
||||
(define* (make-repl lang #:optional debug)
|
||||
|
|
|
@ -76,10 +76,10 @@
|
|||
(syntax-rules ()
|
||||
((_ arg predicate? message)
|
||||
(if (not (predicate? arg))
|
||||
(error "bad argument ~a: ~a" 'arg message)))
|
||||
(error (format #f "bad argument ~a: ~a" 'arg message))))
|
||||
((_ arg predicate?)
|
||||
(if (not (predicate? arg))
|
||||
(error "bad argument ~a: expected ~a" 'arg 'predicate?)))))
|
||||
(error (format #f "bad argument ~a: expected ~a" 'arg 'predicate?))))))
|
||||
|
||||
(define (new-disabled-trap enable disable)
|
||||
(let ((enabled? #f))
|
||||
|
@ -378,7 +378,8 @@
|
|||
current-frame)))
|
||||
procs))
|
||||
(if (null? traps)
|
||||
(error "No procedures found at ~a:~a." file user-line)))
|
||||
(error
|
||||
(format #f "No procedures found at ~a:~a." file user-line))))
|
||||
(lambda (frame)
|
||||
(for-each (lambda (trap) (trap frame)) traps)
|
||||
(set! traps #f)))))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue