Subject line pretty much says it all. By "readably" I do not mean so
that it can be read by the Lisp reader, I mean so that it can be read by
a human. i.e. if I have a simple-error object generated by:
(nth-value 1 (ignore-errors (error "foo ~A" 1)))
is there a portable way to display this object so that it shows up as
"foo 1" rather than e.g. "#<SIMPLE-ERROR #x300041D55A1D>"
Thanks,
rg
Ron Garret <·········@flownet.com> wrote:
+---------------
| Subject line pretty much says it all. By "readably" I do not mean so
| that it can be read by the Lisp reader, I mean so that it can be read by
| a human. i.e. if I have a simple-error object generated by:
|
| (nth-value 1 (ignore-errors (error "foo ~A" 1)))
|
| is there a portable way to display this object so that it shows up
| as "foo 1" rather than e.g. "#<SIMPLE-ERROR #x300041D55A1D>"
+---------------
Sure, just use PRINC (or FORMAT "~A") to print it instead of
the default WRITE (or FORMAT "~S") that your REPL is using:
> (format t "~a" (nth-value 1 (ignore-errors (error "foo ~A" 1))))
Error in function "Top-Level Form": foo 1
NIL
>
-Rob
p.s. By the way, when writing simple CMUCL-based apps ("shell scripts")
for non-programmers to run, I often install the following in
*DEBUGGER-HOOK* so the user only sees the plaintext error and
then aborts [either back to some command-line processor or punts
out altogether] rather than falling into the CL debugger. This
results in nicer messages to the user without totally obscuring
the tracks if I need to debug something later:
> (defun simple-debugger-stub (c hook)
(declare (ignore hook))
(when (find-restart 'abort c)
(format *error-output*
"~&~a~%[Condition of type ~a]~%" c (type-of c))
(abort c)))
> (setf *debugger-hook* #'simple-debugger-stub)
#<Interpreted Function SIMPLE-DEBUGGER-STUB {489F04E9}>
> (defun fail () (error "foo ~A" 1))
FAIL
> (fail)
Error in function FAIL: foo 1
[Condition of type SIMPLE-ERROR]
>
Note: In other than CMUCL you might need to find some other way
to get back to the top-level and/or print the error before looking
for the ABORT restart. [ISTR still getting stuck in the debugger
even with the above in place in at least one older version of CLISP...]
-----
Rob Warnock <····@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
In article <································@speakeasy.net>,
····@rpw3.org (Rob Warnock) wrote:
> Ron Garret <·········@flownet.com> wrote:
> +---------------
> | Subject line pretty much says it all. By "readably" I do not mean so
> | that it can be read by the Lisp reader, I mean so that it can be read by
> | a human. i.e. if I have a simple-error object generated by:
> |
> | (nth-value 1 (ignore-errors (error "foo ~A" 1)))
> |
> | is there a portable way to display this object so that it shows up
> | as "foo 1" rather than e.g. "#<SIMPLE-ERROR #x300041D55A1D>"
> +---------------
>
> Sure, just use PRINC (or FORMAT "~A") to print it instead of
> the default WRITE (or FORMAT "~S") that your REPL is using:
>
Heh, I could have sworn I tried that and it didn't work. But it's
working now. Thanks!
rg
From: Pascal J. Bourguignon
Subject: Re: Is there a portable way to print simple errors readably?
Date:
Message-ID: <8763fx3lmg.fsf@galatea.local>
Ron Garret <·········@flownet.com> writes:
> Subject line pretty much says it all. By "readably" I do not mean so
> that it can be read by the Lisp reader, I mean so that it can be read by
> a human. i.e. if I have a simple-error object generated by:
>
> (nth-value 1 (ignore-errors (error "foo ~A" 1)))
>
> is there a portable way to display this object so that it shows up as
> "foo 1" rather than e.g. "#<SIMPLE-ERROR #x300041D55A1D>"
(princ (nth-value 1 (ignore-errors (error "foo ~A" 1))))
prints:
foo 1
--
__Pascal Bourguignon__