class OpenKey::KeyError

This class is the parent to all opensession errors that originate from the command line.

All opensession cli originating errors are about

Public Class Methods

new(message, culprit) click to toggle source

Initialize the error and provide a culprit object which will be to-stringed and given out as evidence (look at this)!

This method will take care of loggin the error.

@param message [String] human readable error message @param culprit [Object] object that is either pertinent, a culprit or culpable

Calls superclass method
# File lib/keytools/key.error.rb, line 25
def initialize message, culprit

  super(message)

  @the_culprit = culprit

  log.info(x) { "An [Error] Occured => #{message}" }
  log.info(x) { "Object of Interest => #{culprit.to_s}" } unless culprit.nil?
  log.info(x) { "Class Name Culprit => #{culprit.class.name}" }
  log.info(x) { "Error Message From => #{self.class.name}" }

  thread_backtrace = Thread.current.backtrace.join("\n")
  thread_backtrace.to_s.log_lines

end
not_new(the_attribute, the_desc) click to toggle source

Assert that the parameter string attribute is not new which means neither nil, nor empty nor consists solely of whitespace.

The NEW acronym tells us that a bearer worthy of the name is

  • neither Nil

  • nor Empty

  • nor consists solely of Whitespace

@param the_attribute [String]

raise a {KeyError} if the attribute is not new.

@param the_desc [String]

a description of th attribute

@raise [KeyError]

The attribute cannot be NEW. The NEW acronym asserts that the attribute is

  • neither Nil

  • nor Empty

  • nor Whitespace only

# File lib/keytools/key.error.rb, line 77
def self.not_new the_attribute, the_desc

  attribute_new = the_attribute.nil? || the_attribute.chomp.strip.empty?
  return unless attribute_new

  msg = "[the_desc] is either nil, empty or consists solely of whitespace."
  raise KeyError.new( msg, the_desc )

end

Public Instance Methods

culprit() click to toggle source

This method gives interested parties the object that is at the centre of the exception. This object is either very pertinent, culpable or at the very least, interesting.

@return [String] string representation of culpable object

# File lib/keytools/key.error.rb, line 47
def culprit
  return "No culprit identified." if @the_culprit.nil?
  return @the_culprit.to_s
end