GNU bug report logs - #29684
exception printers - request for improvement

Previous Next

Package: guile;

Reported by: David Pirotte <david <at> altosw.be>

Date: Wed, 13 Dec 2017 03:28:02 UTC

Severity: normal

Full log


Message #8 received at 29684 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Llorens <daniel.llorens <at> bluewin.ch>
To: 29684 <at> debbugs.gnu.org
Cc: David Pirotte <david <at> altosw.be>
Subject: Re: bug#29684: exception printers - request for improvement
Date: Thu, 14 Dec 2017 15:38:18 +0100
[Message part 1 (text/plain, inline)]
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
[Message part 2 (text/html, inline)]

This bug report was last modified 6 years and 316 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.