Exception: Omnibus::CommandFailed

Inherits:
Error
  • Object
show all
Defined in:
lib/omnibus/exceptions.rb

Instance Method Summary collapse

Constructor Details

#initialize(cmd) ⇒ CommandFailed

Returns a new instance of CommandFailed.


234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/omnibus/exceptions.rb', line 234

def initialize(cmd)
  status = cmd.exitstatus

  if cmd.environment.nil? || cmd.environment.empty?
    env = nil
  else
    env = cmd.environment.sort.map { |k,v| "#{k}=#{v}" }.join(' ')
  end

  command = cmd.command
  command_with_env = [env, command].compact.join(' ')

  stdout = cmd.stdout.empty? ? '(nothing)' : cmd.stdout.strip
  stderr = cmd.stderr.empty? ? '(nothing)' : cmd.stderr.strip

  super <<-EOH
The following shell command exited with status #{status}:

$ #{command_with_env}

Output:

#{stdout}

Error:

#{stderr}
EOH
end