diff --git a/lib/floe/workflow/states/task.rb b/lib/floe/workflow/states/task.rb index 05b679c44..9d9814b9c 100644 --- a/lib/floe/workflow/states/task.rb +++ b/lib/floe/workflow/states/task.rb @@ -127,7 +127,7 @@ def process_input(input) def parse_error(output) return if output.nil? - JSON.parse(output) + JSON.parse(output.split("\n").last) rescue JSON::ParserError {"Error" => output} end diff --git a/spec/workflow/states/task_spec.rb b/spec/workflow/states/task_spec.rb index 3cbeebca8..f2f9af540 100644 --- a/spec/workflow/states/task_spec.rb +++ b/spec/workflow/states/task_spec.rb @@ -74,6 +74,21 @@ expect(ctx.output).to eq("foo" => {"bar" => "baz"}, "bar" => {"baz" => "foo"}, "response" => ["192.168.1.2"]) end + context "with an error" do + let(:success) { false } + + it "uses the last error line as output if it is JSON" do + expect(mock_runner) + .to receive(:run_async!) + .with(resource, {"foo" => {"bar" => "baz"}, "bar" => {"baz" => "foo"}}, nil) + expect(mock_runner).to receive("output").and_return("ABCD\nHELLO\n{\"Error\":\"Custom Error\"}") + + workflow.current_state.run_nonblock! + + expect(ctx.output).to eq({"Error" => "Custom Error"}) + end + end + it "returns nil if the output isn't JSON" do expect(mock_runner) .to receive(:run_async!)