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.



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/omnibus/exceptions.rb', line 246

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