From bcacf8f76fb06129f2bbc760baf38fa5e2e814fc Mon Sep 17 00:00:00 2001
From: Arun Isaac
Date: Wed, 24 Jun 2026 04:14:18 +0100
Subject: ccwl: Make all exceptions continuable.
---
ccwl/ccwl.scm | 478 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 250 insertions(+), 228 deletions(-)
diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm
index a2d9ea2..0de03e4 100644
--- a/ccwl/ccwl.scm
+++ b/ccwl/ccwl.scm
@@ -25,7 +25,8 @@
(define-module (ccwl ccwl)
#:use-module ((rnrs conditions) #:select (condition
condition-irritants))
- #:use-module ((rnrs exceptions) #:select (guard (raise . raise-exception)))
+ #:use-module ((rnrs exceptions) #:select (raise-continuable
+ guard))
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-2)
#:use-module (srfi srfi-9)
@@ -138,7 +139,7 @@ compared using @code{equal?}."
;; TODO: If tree is a quoted expression, emit a warning.
(unless (false-if-exception
(scm->yaml-string (syntax->datum tree)))
- (raise-exception
+ (raise-continuable
(condition (ccwl-violation tree)
(formatted-message (string-append parameter-name
" parameter not serializable to YAML"))))))
@@ -162,55 +163,60 @@ compared using @code{equal?}."
"Return syntax to build an object from INPUT-SPEC."
(syntax-case input-spec ()
((id args ...)
- (guard (exception
- ((unrecognized-keyword-assertion? exception)
- (raise-exception
- (match (condition-irritants exception)
- ((irritant _ ...)
- (condition (ccwl-violation irritant)
- (formatted-message "Unrecognized keyword argument ~a in input"
- (syntax->datum irritant)))))))
- ((invalid-keyword-arity-assertion? exception)
- (raise-exception
- (match (condition-irritants exception)
- ;; TODO: Report all extra arguments, not just the
- ;; first one.
- ((keyword _ extra _ ...)
- (condition (ccwl-violation extra)
- (formatted-message "Unexpected extra argument ~a for unary keyword argument ~a"
- (syntax->datum extra)
- (syntax->datum keyword)))))))
- ((invalid-positional-arguments-arity-assertion? exception)
- (raise-exception
- (match (condition-irritants exception)
- ;; TODO: Report all extra positional arguments, not
- ;; just the first one.
- ((id extra _ ...)
- (condition (ccwl-violation extra)
- (formatted-message "Unexpected extra positional argument ~a in input"
- (syntax->datum extra))))
- (()
- (condition (ccwl-violation input-spec)
- (formatted-message "Input has no identifier")))))))
- (apply (syntax-lambda** (id #:key (type #'File) label (default (make-unspecified-default)) (stage? #'#f) (other #'()))
- (unless (memq (syntax->datum stage?)
- (list #t #f))
- (raise-exception
- (condition (ccwl-violation stage?)
- (formatted-message "Invalid #:stage? parameter ~a. #:stage? must either be #t or #f."
- (syntax->datum stage?)))))
- (ensure-yaml-serializable other "#:other")
- (let ((position #f)
- (prefix #f))
- #`(make-input '#,id
- #,(construct-type-syntax type)
- #,label
- #,(if (unspecified-default? default)
- #'(make-unspecified-default)
- default)
- #,position #,prefix #f #f
- #,stage? '#,other)))
- #'(id args ...))))
+ (with-exception-handler
+ (lambda (c)
+ (cond
+ ((unrecognized-keyword-assertion? c)
+ (raise-continuable
+ (match (condition-irritants c)
+ ((irritant _ ...)
+ (condition (ccwl-violation irritant)
+ (formatted-message "Unrecognized keyword argument ~a in input"
+ (syntax->datum irritant)))))))
+ ((invalid-keyword-arity-assertion? c)
+ (raise-continuable
+ (match (condition-irritants c)
+ ;; TODO: Report all extra arguments, not just the
+ ;; first one.
+ ((keyword _ extra _ ...)
+ (condition (ccwl-violation extra)
+ (formatted-message "Unexpected extra argument ~a for unary keyword argument ~a"
+ (syntax->datum extra)
+ (syntax->datum keyword)))))))
+ ((invalid-positional-arguments-arity-assertion? c)
+ (raise-continuable
+ (match (condition-irritants c)
+ ;; TODO: Report all extra positional arguments, not
+ ;; just the first one.
+ ((id extra _ ...)
+ (condition (ccwl-violation extra)
+ (formatted-message "Unexpected extra positional argument ~a in input"
+ (syntax->datum extra))))
+ (()
+ (condition (ccwl-violation input-spec)
+ (formatted-message "Input has no identifier"))))))
+ (else
+ (raise-continuable c))))
+ (cut apply
+ (syntax-lambda** (id #:key (type #'File) label (default (make-unspecified-default)) (stage? #'#f) (other #'()))
+ (unless (memq (syntax->datum stage?)
+ (list #t #f))
+ (raise-continuable
+ (condition (ccwl-violation stage?)
+ (formatted-message "Invalid #:stage? parameter ~a. #:stage? must either be #t or #f."
+ (syntax->datum stage?)))))
+ (ensure-yaml-serializable other "#:other")
+ (let ((position #f)
+ (prefix #f))
+ #`(make-input '#,id
+ #,(construct-type-syntax type)
+ #,label
+ #,(if (unspecified-default? default)
+ #'(make-unspecified-default)
+ default)
+ #,position #,prefix #f #f
+ #,stage? '#,other)))
+ #'(id args ...))))
(id (identifier? #'id) (input #'(id)))
(_ (error "Invalid input:" (syntax->datum input-spec)))))
@@ -227,43 +233,49 @@ compared using @code{equal?}."
"Return syntax to build an