Skip to content

Commit

Permalink
improve error message when last arg to flow is a vector
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Jun 8, 2020
1 parent 3df23c7 commit 421e22a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/state_flow/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
[{:keys [description caller-meta]} & flows]
(when-not (string-expr? description)
(throw (IllegalArgumentException. "The first argument to flow must be a description string")))
(when (vector? (last flows))
(throw (ex-info "The last argument to flow must be a flow/step, not a binding vector." {})))
(let [flow-meta caller-meta
flows' (or flows `[(m/return nil)])]
`(m/do-let
Expand Down
22 changes: 16 additions & 6 deletions test/state_flow/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
(def empty-flow
(flow "empty"))

(deftest test-flow
(testing "flow without description fails at macro-expansion time"
(is (re-find #"first argument .* must be .* description string"
(try
(macroexpand `(flow (state/return {})))
(catch clojure.lang.Compiler$CompilerException e
(.. e getCause getMessage))))))

(testing "flow with vector as last argument fails at macro-expansion time"
(is (re-find #"last argument .* must be a flow/step"
(try
(macroexpand `(flow "" [x (state/get-state)]))
(catch clojure.lang.Compiler$CompilerException e
(.. e getCause getMessage)))))))

(deftest run-flow
(testing "default initial state is an empty map"
(is (= {}
Expand All @@ -49,12 +64,7 @@
(testing "empty flow runs without exception"
(is (nil? (first (state-flow/run empty-flow {})))))

(testing "flow without description fails at macro-expansion time"
(is (re-find #"first argument .* must be .* description string"
(try
(macroexpand `(flow (state/return {})))
(catch clojure.lang.Compiler$CompilerException e
(.. e getCause getMessage))))))


(testing "flow with a `(str ..)` expr for the description is fine"
(is (macroexpand `(flow (str "foo") [original (state/gets :value)
Expand Down

0 comments on commit 421e22a

Please sign in to comment.