Skip to content

Commit b4b57a6

Browse files
committed
Return errors from run-commands
1 parent f2fbcfe commit b4b57a6

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/commands.janet

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@
4343
(map (fn [build-command] (build-command arguments file-path))
4444
commands)))
4545

46+
# TODO: Replace reduce with something else.
4647
(defn run-commands [plan file-path arguments]
4748
(def commands (build-commands arguments file-path))
4849
(def errors (filter identity (flatten (map (fn [c] (c :errors)) commands))))
49-
(if (any? errors)
50-
(do
51-
(errors/print-errors-without-status-code errors)
52-
plan)
53-
(reduce (fn [new-plan command-and-arguments]
54-
(def command (first (command-and-arguments :command)))
55-
(def arguments (drop 1 (command-and-arguments :command)))
56-
(apply command new-plan arguments))
57-
plan
58-
commands)))
50+
(var new-plan plan)
51+
(if (empty? errors)
52+
(set new-plan (reduce (fn [new-plan command-and-arguments]
53+
(def command (first (command-and-arguments :command)))
54+
(def arguments (drop 1 (command-and-arguments :command)))
55+
(apply command new-plan arguments))
56+
plan
57+
commands)))
58+
{:plan new-plan :errors errors})

test/commands_test.janet

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@
5454
(day/build-day (d/date 2020 8 2) @[]
5555
@[(task/build-task "Buy milk" true)])]))
5656
(def arguments {"skip-backup" true "remove-empty-days" true "insert-days" "3"})
57-
(def new-plan (run-commands plan file-path arguments))
57+
(def {:plan new-plan :errors errors} (run-commands plan file-path arguments))
5858
(def days (new-plan :days))
59+
(test (empty? errors) true)
5960
(test (length days) 4)
6061
(test (= (d/+days today 2) ((days 0) :date)) true)
6162
(test (= (d/+days today 1) ((days 1) :date)) true)
@@ -70,9 +71,10 @@
7071
(day/build-day (d/date 2020 8 2) @[]
7172
@[(task/build-task "Buy milk" true)])]))
7273
(def arguments {"skip-backup" true "remove-empty-days" true "insert-days" "three"})
73-
(def new-plan (run-commands plan file-path arguments))
74+
(def {:plan new-plan :errors errors} (run-commands plan file-path arguments))
7475
(def days (new-plan :days))
7576
(test (length days) 3)
7677
(test (= today ((days 0) :date)) true)
7778
(test (= (d/date 2020 8 4) ((days 1) :date)) true)
78-
(test (= (d/date 2020 8 2) ((days 2) :date)) true))
79+
(test (= (d/date 2020 8 2) ((days 2) :date)) true)
80+
(test (= (first errors) "--insert-days argument is not a number.") true))

0 commit comments

Comments
 (0)