aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2026-03-04 20:23:54 -0600
committerCalvin Rose <calsrose@gmail.com>2026-03-04 20:24:26 -0600
commit149ae5409e6674ccd6786ddf6842b4e4373dc503 (patch)
tree873320d609ee366f8bdc723be37ea00149121dae
parentInclude `spork/date` in `spork\init.janet` (diff)
Use try instead of edefer for error handling in build rules.
Simplifies the control flow.
-rw-r--r--spork/build-rules.janet35
1 files changed, 23 insertions, 12 deletions
diff --git a/spork/build-rules.janet b/spork/build-rules.janet
index a45115e..f4d6ffe 100644
--- a/spork/build-rules.janet
+++ b/spork/build-rules.janet
@@ -119,18 +119,29 @@
(def rule (get all-targets target))
(def dependent-set (get dependents target ()))
(def r (assert (get rule :recipe)))
- (edefer
- (do
- (each o (get rule :outputs [])
- (protect (os/rm o)))
- (repeat n-workers (ev/give q nil)))
- # Check that all inputs exists
- (make-sure-exists rules " is missing as input" (get rule :inputs []))
- (if (indexed? r)
- (each rr r (rr))
- (r))
- # Make sure all outputs were created
- (make-sure-exists rules " was not created by the rule" (get rule :outputs [])))
+
+ (def result
+ (try
+ (do
+ # Check that all inputs exists
+ (make-sure-exists rules " is missing as input" (get rule :inputs []))
+ (if (indexed? r)
+ (each rr r (rr))
+ (r))
+ # Make sure all outputs were created
+ (make-sure-exists rules " was not created by the rule" (get rule :outputs []))
+ :good)
+ ([err f]
+ (debug/stacktrace f err (string/format "rule %V failed: " target))
+ :bad)))
+
+ (when (= :bad result)
+ (each o (get rule :outputs [])
+ (protect (os/rm o)))
+ (repeat n-workers (ev/give q nil))
+ (set work-count 0)
+ (break))
+
(array/push targets-built target)
(eachk next-target dependent-set
(-- (dep-counts next-target))