Right now, the REPL will catch either general exceptions or calls to error or scm-error which throw specific exception types. For general exceptions the argument list is just printed with ~a, but for libguile exceptions, the handler expects a ‘format’ argument which is used to format the error message. One can put ~a and ~s in this ‘format’ argument, see
https://www.gnu.org/software/guile/manual/html_node/Handling-Errors.html.
(use-modules (ice-9 pretty-print))
(when (defined? 'exception-format)
(set! exception-format
(lambda (port fmt . args)
(for-each (lambda (arg)
(truncated-print arg #:port port))
args))))
throws away this formatting. That's why I proposed instead the other solution in the links above, which replaces the ~a and ~s by ~y (this calls truncated print), but otherwise respects the original format string.
(set! exception-format
(lambda (port fmt . args)
(apply format port (rewrite-fmt (rewrite-fmt fmt "~s") "~a") args)))
Anyway. These are clunky hacks. According to the manual
~A
indicates an
argument printed using display
, while ~S
indicates an
argument printed using write
I think this is an unnecessary complication if there's a hook. One option (that works like ‘write’ by default) is enough. If one wants to craft a special error message, that should be done without abusing the exception arguments.
I think this ‘write’ should be a hook or even a fluid. There is already a hook to configure the REPL printer, which is set by (repl-default-option-set! 'print ##) or (repl-option-set! repl 'print ##) (the latter is undocumented). Maybe that hook can be reused for the exception printer. Or maybe there can be a new hook that is reused by both the repl and the exception printer. It makes sense to me to make both of these refer to the same function.
I also agree with David that both the REPL and the exception printers should be truncated by default. That requires truncated-print to be available in (ice-9 boot).
Anyway, just some thoughts.