Add documentation for lots of the "undocumented" bits
All checks were successful
/ test (push) Successful in 6s

In the Guile Documenta generated documentation.
This commit is contained in:
Christopher Baines 2026-03-23 11:56:53 +00:00
parent d282841a78
commit d0ff89023b
8 changed files with 140 additions and 5 deletions

View file

@ -41,14 +41,20 @@
(define make-knots-exception
(record-constructor &knots-exception))
(set-procedure-property! make-knots-exception 'documentation
"Construct a @code{&knots-exception} with the given stack.")
(define knots-exception?
(exception-predicate &knots-exception))
(set-procedure-property! knots-exception? 'documentation
"Return @code{#t} if OBJ is a @code{&knots-exception}.")
(define knots-exception-stack
(exception-accessor
&knots-exception
(record-accessor &knots-exception 'stack)))
(set-procedure-property! knots-exception-stack 'documentation
"Return the stack from a @code{&knots-exception}.")
(define (backtrace-debug-mode?)
(let ((val (getenv "KNOTS_BACKTRACE_DEBUG")))
@ -222,6 +228,34 @@
(define* (print-backtrace-and-exception/knots
exn
#:key (port (current-error-port)))
"Print the backtrace and exception information from EXN to PORT. This
procedure captures the stack, so should be run before the stack is
unwound, so using @code{with-exception-handler} without
@code{#:unwind? #t}, the exception may need to then be re-raised and
handled in an outer exception handler.
@example
(with-exception-handler
(lambda (exn)
;; Recover from the exception
#f)
(lambda ()
(with-exception-handler
(lambda (exn)
(print-backtrace-and-exception/knots exn)
(raise-exception exn))
(lambda ()
(do-things))))
#:unwind? #t)
@end example
It's important to use @code{print-backtrace-and-exception/knots} for
displaying backtraces involving functionality from Guile Knots, since
the stack involved is potentially split across several fibers. The
stacks involved are attached to the exception, and this procedure
extracts this information out and assembles a backtrace including all
the code involved.
"
(define (get-string out stack)
(let* ((stack-vector (stack->vector stack))
(knots-stack-vectors