Exception: SafeDb::KeyError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/utils/key.error.rb

Overview

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

All openbranch cli originating errors are about

  • a problem with the input or

  • a problem with the current state or

  • a predictable future problem

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, culprit) ⇒ KeyError

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.

Parameters:

  • message (String)

    human readable error message

  • culprit (Object)

    object that is either pertinent, a culprit or culpable



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/utils/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

Class Method Details

.not_new(the_attribute, the_desc) ⇒ Object

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

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

  • neither Nil

  • nor Empty

  • nor Whitespace only

Parameters:

Raises:



77
78
79
80
81
82
83
84
85
# File 'lib/utils/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

Instance Method Details

#culpritString

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.

Returns:

  • (String)

    string representation of culpable object



47
48
49
50
# File 'lib/utils/key.error.rb', line 47

def culprit
  return "No culprit identified." if @the_culprit.nil?
  return @the_culprit.to_s
end