From 80d4055e4213763e2d3a0bfcc39d6b55c52f5415 Mon Sep 17 00:00:00 2001 From: Michael Käppler Date: Tue, 2 Apr 2024 08:58:52 +0200 Subject: Fix error messages containing format strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- module/srfi/srfi-37.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/srfi/srfi-37.scm') diff --git a/module/srfi/srfi-37.scm b/module/srfi/srfi-37.scm index 9b57ac1c2..cd37f981e 100644 --- a/module/srfi/srfi-37.scm +++ b/module/srfi/srfi-37.scm @@ -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: -- cgit v1.2.3