From 3063c33634d4a25ba99a2c884dd8bf04e519f914 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 14 Oct 2023 00:55:57 +0100 Subject: ccwl: Detect multiple expressions in workflow body. * ccwl/ccwl.scm (workflow): Detect multiple expressions in workflow body and raise an exception. * tests/ccwl.scm ("unrecognized workflow syntaxes must raise a &ccwl-violation condition"): Test for the formatted message too. ("multiple expressions in workflow body must raise a &ccwl-violation condition"): New test. --- ccwl/ccwl.scm | 12 ++++++++++++ tests/ccwl.scm | 14 +++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm index d9d9c78..f64830c 100644 --- a/ccwl/ccwl.scm +++ b/ccwl/ccwl.scm @@ -615,6 +615,18 @@ a object, in STEPS, a list of objects. If no such (list #,@(filter-map (cut key->output <> steps) output-keys)) '()))) + ;; Guess that these are multiple unconnected expressions in the + ;; workflow body, and try to produce a helpful error message. + ((_ (inputs ...) expressions ...) + (raise-exception + (condition + (ccwl-violation x) + (formatted-message "More than one expression ~a in workflow body. Perhaps you need to combine them with a pipe or a tee?" + (string-join + (map (lambda (expression) + (call-with-output-string + (cut write expression <>))) + (syntax->datum #'(expressions ...)))))))) (x (raise-exception (condition (ccwl-violation #'x) diff --git a/tests/ccwl.scm b/tests/ccwl.scm index cd78739..76bcecd 100644 --- a/tests/ccwl.scm +++ b/tests/ccwl.scm @@ -177,7 +177,19 @@ (test-assert "unrecognized workflow syntaxes must raise a &ccwl-violation condition" (guard (exception - (else (ccwl-violation? exception))) + (else (and (ccwl-violation? exception) + (string=? (formatted-message-format exception) + "Unrecognized workflow syntax [expected (workflow (input ...) tree)]")))) + (begin (macroexpand + '(workflow foo ((message #:type string)) + (print #:message message))) + #f))) + +(test-assert "multiple expressions in workflow body must raise a &ccwl-violation condition" + (guard (exception + (else (and (ccwl-violation? exception) + (string=? (formatted-message-format exception) + "More than one expression ~a in workflow body. Perhaps you need to combine them with a pipe or a tee?")))) (begin (macroexpand '(workflow ((message1 #:type string) (message2 #:type string)) -- cgit v1.2.3