Readable messages for host conditions

clojure.test reported a host-condition crash with a blank message (ex-message is
nil for non-ex-info conditions); fall back to jolt.host/condition-message.
condition-message itself left a Chez format-template message (open-input-file's
'failed for ~a: ~(~a~)') unformatted; apply its irritants.
This commit is contained in:
Yogthos 2026-06-24 11:03:34 -04:00
parent 7947918919
commit 79d0084163
2 changed files with 25 additions and 6 deletions

View file

@ -255,10 +255,21 @@
;; &message text plus any &irritants, or display-condition output as a fallback.
(define (condition->message-string c)
(if (message-condition? c)
(let ((m (condition-message c))
(irr (if (irritants-condition? c) (condition-irritants c) '())))
(let loop ((xs irr) (acc m))
(if (null? xs) acc (loop (cdr xs) (string-append acc " " (jolt-pr-str (car xs)))))))
(let* ((m (condition-message c))
(irr (if (irritants-condition? c) (condition-irritants c) '()))
(append-irr (lambda ()
(let loop ((xs irr) (acc m))
(if (null? xs) acc
(loop (cdr xs) (string-append acc " " (jolt-pr-str (car xs)))))))))
;; some Chez conditions (open-input-file etc.) carry a format-template
;; message ("failed for ~a: ~(~a~)") whose irritants fill the directives;
;; format it in. Fall back to appending the irritants if that fails.
(if (and (string? m) (let scan ((i 0))
(cond ((>= i (string-length m)) #f)
((char=? (string-ref m i) #\~) #t)
(else (scan (+ i 1))))))
(guard (e (#t (append-irr))) (apply format m irr))
(append-irr)))
(with-output-to-string (lambda () (display-condition c)))))
;; expose a Chez condition's message to Clojure (ex-message returns nil for raw
;; host conditions): the nREPL eval handler surfaces it instead of an opaque