Skip to content

Commit

Permalink
Append a caught exception to the dynamic output of a step instead of …
Browse files Browse the repository at this point in the history
…discarding the dynamic output (fixes #174)
  • Loading branch information
flosell committed Nov 5, 2017
1 parent f4e6b49 commit 62e2870
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,12 @@ This changelog contains a loose collection of changes in every release. I will a

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to a "shifted" version of semantic versioning while the major version remains at 0: Minor version changes indicate breaking changes, patch version changes should not contain breaking changes.

## 0.13.5

### Fixed

* Output of steps that throw an exception gets lost (#174)

## 0.13.4

### Fixed
Expand Down
10 changes: 8 additions & 2 deletions src/clj/lambdacd/execution/internal/execute_step.clj
Expand Up @@ -28,7 +28,9 @@
(try
(handler args ctx)
(catch Exception e
{:status :failure :out (util-exceptions/stacktrace-to-string e)}))))
{:status :failure
:out (util-exceptions/stacktrace-to-string e)
::append-out-to-async-out true}))))

; ============================================

Expand Down Expand Up @@ -98,7 +100,11 @@
immediate-step-result (handler args ctx-for-child)
processed-async-result (async/<!! processed-async-result-ch)
complete-step-result (merge processed-async-result immediate-step-result)]
complete-step-result)))
(if (::append-out-to-async-out immediate-step-result)
(-> complete-step-result
(assoc :out (str (:out processed-async-result) (:out immediate-step-result)))
(dissoc ::append-out-to-async-out))
complete-step-result))))

; ============================================

Expand Down
12 changes: 10 additions & 2 deletions test/clj/lambdacd/execution/internal/execute_step_test.clj
Expand Up @@ -33,9 +33,16 @@

(def message-thrown-by-some-step-throwing-an-exception
"Something went wrong!")
(def output-written-before-throwing-an-exception
"some output before throwing exception")

(defn some-step-throwing-an-exception [& _]
(throw (Exception. ^String message-thrown-by-some-step-throwing-an-exception)))

(defn some-step-writing-output-then-throwing-an-exception [_ {c :result-channel}]
(async/>!! c [:out output-written-before-throwing-an-exception])
(throw (Exception. ^String message-thrown-by-some-step-throwing-an-exception)))

(defn some-step-throwing-an-error [& _]
(throw (Error. ^String message-thrown-by-some-step-throwing-an-exception)))

Expand Down Expand Up @@ -163,9 +170,10 @@
(testing "that the result indicates that a step has been waiting"
(is (= {:outputs { [0 0] {:status :success :has-been-waiting true}} :status :success} (execute-step {} [(some-ctx-with :step-id [0 0]) some-step-sending-a-wait] ))))
(testing "that if an exception is thrown in the step, it will result in a failure and the exception output is logged"
(let [output (execute-step {} [(some-ctx-with :step-id [0 0]) some-step-throwing-an-exception])]
(let [output (execute-step {} [(some-ctx-with :step-id [0 0]) some-step-writing-output-then-throwing-an-exception])]
(is (= :failure (get-in output [:outputs [0 0] :status])))
(is (.contains (get-in output [:outputs [0 0] :out]) "Something went wrong"))))
(is (.contains (get-in output [:outputs [0 0] :out]) message-thrown-by-some-step-throwing-an-exception))
(is (.contains (get-in output [:outputs [0 0] :out]) output-written-before-throwing-an-exception))))
(testing "that the context passed to the step contains an output-channel and that results passed into this channel are merged into the result"
(is (= {:outputs { [0 0] {:out "hello world" :status :success}} :status :success} (execute-step {} [(some-ctx-with :step-id [0 0]) some-step-writing-to-the-result-channel]))))
(testing "that the context data is being passed on to the step"
Expand Down

0 comments on commit 62e2870

Please sign in to comment.