Skip to content

Commit

Permalink
for task errors, use the json on the last line
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Oct 6, 2023
1 parent 1eb25f2 commit 6cdcf85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/floe/workflow/states/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/workflow/states/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand Down

0 comments on commit 6cdcf85

Please sign in to comment.