about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorArun Isaac2026-06-22 23:30:02 +0100
committerArun Isaac2026-06-22 23:30:02 +0100
commit990f426f7d76e17168acdf5580254af443351d8c (patch)
treef5fb8bab689a3a7268d34fe152074e693c003b60 /scripts
parentc7d88c69d0a7e87c21eab967ae5cbef5943c0518 (diff)
downloadccwl-990f426f7d76e17168acdf5580254af443351d8c.tar.gz
ccwl-990f426f7d76e17168acdf5580254af443351d8c.tar.lz
ccwl-990f426f7d76e17168acdf5580254af443351d8c.zip
scripts: Handle read errors in a specialized reader.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/ccwl30
1 files changed, 18 insertions, 12 deletions
diff --git a/scripts/ccwl b/scripts/ccwl
index e7e9b6d..b20a136 100755
--- a/scripts/ccwl
+++ b/scripts/ccwl
@@ -67,6 +67,23 @@ exec guile --no-auto-compile -e main -s "$0" "$@"
                   (acons 'output-file arg result)))
         %help-option))
 
+(define* (ccwl-read #:optional (port (current-input-port)))
+  "Read an S-expression from @var{port}. This function wraps
+@code{read-syntax} to raise read errors the way ccwl likes to handle
+it."
+  (guard (c ((and (eq? (exception-kind c)
+                       'read-error)
+                  (message-condition? c)
+                  (irritants-condition? c))
+             ;; TODO: Once https://codeberg.org/guile/guile/issues/206
+             ;; is fixed, report error in source context using
+             ;; report-ccwl-violation.
+             (raise-exception
+              (apply formatted-message
+                     (condition-message c)
+                     (condition-irritants c)))))
+    (read-syntax port)))
+
 (define (ccwl-compile source to port)
   "Compile @var{source} file to @var{to} format writing output to
 @var{port}. @var{to} is either @code{'cwl} or @code{'dot}."
@@ -94,7 +111,7 @@ exec guile --no-auto-compile -e main -s "$0" "$@"
                      (call-with-current-directory (dirname source-path)
                        (lambda ()
                          (load source-path
-                               read-syntax)))))))
+                               ccwl-read)))))))
      (if (or (command? result)
              (js-expression? result)
              (workflow? result))
@@ -115,17 +132,6 @@ exec guile --no-auto-compile -e main -s "$0" "$@"
         (cond
          ((formatted-message? condition)
           (report-formatted-message condition))
-         ((and (eq? (exception-kind condition)
-                    'read-error)
-               (message-condition? condition)
-               (irritants-condition? condition))
-          ;; TODO: Once https://codeberg.org/guile/guile/issues/206 is
-          ;; fixed, report error in source context using
-          ;; report-ccwl-violation.
-          (report-formatted-message
-           (apply formatted-message
-                  (condition-message condition)
-                  (condition-irritants condition))))
          ((not (quit-exception? condition))
           (display "You have discovered a bug! ccwl crashed! :-(
 Please report this to ccwl@systemreboot.net