DEFSTRUCT's :PRINT-OBJECT and (nested) printer errors
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Confirmed
|
Low
|
Unassigned |
Bug Description
Specifying an explicit print-function for a structure results in cryptic
errors if that print function signals errors.
Minimal test case:
(defun print-bar (obj stream)
(error "PRINT-BAR: ~S~%" obj))
(defstruct (bar (:print-object print-bar))
a b c)
then type (MAKE-BAR) at the REPL. The resulting error message is
Unable to display error condition
In the actual case I was bitten by this the backtrace didn't look as
good as in this simple case, and pressing `C' in SLDB wasn't useful at
all.
Perhaps the PRINT-OBJECT method that is generated by DEFSTRUCT should
look more like the following
(defmethod print-object ((obj bar) stream)
(if (boundp '%error-
(format stream "[PRINT ERROR]"))
(error (e)
(let ((%error-
We should generally speaking review treatment of errors during PRINT-OBJECT and document some guidelines on how to write robust PRINT-OBJECT methods, and how to debug problems with hairy ones.