bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#29684: exception printers - request for improvement


From: Daniel Llorens
Subject: bug#29684: exception printers - request for improvement
Date: Thu, 14 Dec 2017 15:38:18 +0100


Agreed with David that this is an important issue. Without a patch, working with a large data structure is guaranteed to kill the REPL session sooner or later. There was a thread a while ago here: https://lists.gnu.org/archive/html/guile-user/2017-02/msg00188.html

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.

The proposal

(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.

See the related bug#29669 about REPL printers. 

Regards

Daniel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]