Module: Unravel

Defined in:
lib/unravel.rb,
lib/unravel/exec.rb,
lib/unravel/version.rb

Overview

TODO: don’t allow replacing the error

Defined Under Namespace

Classes: Exec, HumanInterventionNeeded, NoErrorHandler, NoKnownRootCause, Registry, SameCauseReoccurringCause, Session

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.Capture(args) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/unravel/exec.rb', line 56

def Capture(args)
  Unravel.logger.debug "  -> Running: #{args.inspect}"
  out, error, status = Open3.capture3(*args)
  return out if status.success?
  Unravel.logger.debug "Errors from #{args.inspect}: -----"
  Unravel.logger.debug "#{error}"
  error = out if error.strip.empty?
  raise Exec::Error::Standard, error
rescue Errno::ENOENT => e
  raise Exec::Error::ENOENT, e.message
end

.Exec(args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/unravel/exec.rb', line 40

def Exec(args)
  Unravel.logger.debug "  -> Running: #{args.inspect}"
  out, error, status = Open3.capture3(*args)
  Unravel.logger.debug "Output from #{args.inspect}: -----"
  Unravel.logger.debug "#{out}"
  return true if status.success?
  Unravel.logger.debug "Errors from #{args.inspect}: -----"
  Unravel.logger.debug "#{error}"

  # TODO: is strip a good idea?
  raise Exec::Error::Silent.new(status.exitstatus, out) if error.strip.empty?
  raise Exec::Error::Standard, error
rescue Errno::ENOENT => e
  raise Exec::Error::ENOENT, e.message
end

.loggerObject



11
12
13
14
15
16
17
18
# File 'lib/unravel.rb', line 11

def self.logger
  @@logger ||= Logger.new(STDOUT).tap do |logger|
    logger.level = Logger::DEBUG
    logger.formatter = proc do |severity, datetime, progname, msg|
      "#{severity}: #{msg}\n"
    end
  end
end

.run(*args) ⇒ Object



36
37
38
# File 'lib/unravel/exec.rb', line 36

def run(*args)
  Exec(args)
end