Skip to content

Commit 59da6c0

Browse files
joewilliamsdanielsdeleo
authored andcommitted
raise an exception in certain conditions
1 parent 77b5614 commit 59da6c0

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

chef/lib/chef/exceptions.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Application < RuntimeError; end
2525
class Cron < RuntimeError; end
2626
class Env < RuntimeError; end
2727
class Exec < RuntimeError; end
28+
class ErlCall < RuntimeError; end
2829
class FileNotFound < RuntimeError; end
2930
class Package < RuntimeError; end
3031
class Service < RuntimeError; end

chef/lib/chef/provider/erl_call.rb

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,31 @@ def action_run
6565
@new_resource.code.each_line { |line| stdin.puts(line.chomp) }
6666

6767
stdin.close
68-
69-
Chef::Log.info("Ran erl_call[#{@new_resource.name}] successfully")
68+
7069
Chef::Log.debug("erl_call[#{@new_resource.name}] output: ")
71-
72-
stdout.each_line { |line| Chef::Log.debug("#{line}")}
73-
stderr.each_line { |line| Chef::Log.debug("#{line}")}
70+
71+
stdout_output = ""
72+
stdout.each_line { |line|
73+
Chef::Log.debug("#{line}")
74+
stdout_output << line
75+
}
7476
stdout.close
77+
78+
stderr_output = ""
79+
stderr.each_line { |line|
80+
Chef::Log.debug("#{line}")
81+
stderr_output << line
82+
}
7583
stderr.close
84+
85+
if stdout_output.include?('{ok,')
86+
Chef::Log.info("Ran erl_call[#{@new_resource.name}] successfully")
87+
elsif stderr_output.length > 0
88+
raise Chef::Exceptions::ErlCall, stderr_output
89+
else
90+
raise Chef::Exceptions::ErlCall, stdout_output
91+
end
92+
7693
ensure
7794
Process.wait(pid) if pid
7895
end

0 commit comments

Comments
 (0)