Skip to content

Commit

Permalink
Raise CommandError when shell command fails
Browse files Browse the repository at this point in the history
In the effort to make Buffet resilient to hosts going down, it was first
identified that we swallow all failures in external shell commands. This
becomes problematic if we want to bubble up the failure to the Master to
properly handle.

The solution was to add a `CommandError` exception that would wrap the
result of a shell command in the event a non-zero exit status was
returned.

Related Story:
  http://www.pivotaltracker.com/story/show/40166629
  ("Buffet should gracefully continue when a node is down")

Change-Id: I22f433d352c524637860f5a4c8a19285fa9cae67
Reviewed-on: https://gerrit.causes.com/16102
Reviewed-by: Lann Martin <lann@causes.com>
Reviewed-by: Aiden Scandella <aiden@causes.com>
Tested-by: Shane da Silva <shane@causes.com>
  • Loading branch information
Shane da Silva committed Dec 7, 2012
1 parent 150423d commit 3d02d74
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/buffet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module Buffet
autoload :Settings, 'buffet/settings'
autoload :Slave, 'buffet/slave'

class CommandError < StandardError; end

def self.log_dir
@log_dir ||= Pathname.new(ENV['HOME']) + '.buffet/log'
end
Expand All @@ -33,8 +35,10 @@ def self.runner
def self.run! *command
result = runner.run *command
unless result.success?
logger.error 'exiting due to non-zero exit status'
exit result.status
message = "`#{command.join(' ')}` exited with non-zero status: #{result.status}"
message += "\nSTDOUT: #{result.stdout}" unless result.stdout.empty?
message += "\nSTDERR: #{result.stderr}" unless result.stderr.empty?
raise CommandError.new(message)
end
result
end
Expand Down

0 comments on commit 3d02d74

Please sign in to comment.