Module: GreeErr

Defined in:
lib/rest-object/gree_err.rb

Class Method Summary collapse

Class Method Details

.msg_not_identical(value_name, var1, var2) ⇒ Object

Construct an error message string saying 2 things are not identical



11
12
13
# File 'lib/rest-object/gree_err.rb', line 11

def self.msg_not_identical(value_name, var1, var2)
    return "#{value_name} is not identical: #1 = #{value_1}, #2 = #{value_2}"
end

.msg_unsupported(value_name, value) ⇒ Object

Construct an error message string saying something has an unsupported value



16
17
18
# File 'lib/rest-object/gree_err.rb', line 16

def self.msg_unsupported(value_name, value)
    return "Unsupported #{value_name}: '#{value}'"
end

.not_identical_raise(value_name, value_1, value_2) ⇒ Object

Raise a RuntimeError when 2 things are not identical

Raises:

  • (RuntimeError)


21
22
23
# File 'lib/rest-object/gree_err.rb', line 21

def self.not_identical_raise(value_name, value_1, value_2)
    raise RuntimeError, self.msg_not_identical(value_name, value_1, value_2), caller
end

.raise(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rest-object/gree_err.rb', line 25

def self.raise(*args)
    _log_message = ""
    # look for a backtrace to include
    for _arg in args
        if _arg.respond_to? :backtrace
            _log_message << "  " << _arg.backtrace.join("\n  ")
        end
    end
    # if no backtrace found, add generic
    if _log_message == ""
        _log_message << "  " << caller.join("\n  ")
    end
    _log_message = "Exception-> " + args.pretty_inspect + _log_message
    GreeLog.error(previous_function_name + "()") {
        _log_message
    }
    Kernel.raise *args
end

.unsupported_raise(value_name, value) ⇒ Object

Raise an ArgumentError when an argument has unsupported value

Raises:

  • (ArgumentError)


45
46
47
# File 'lib/rest-object/gree_err.rb', line 45

def self.unsupported_raise(value_name, value)
    raise ArgumentError, self.msg_unsupported(value_name, value), caller
end

.with_ignored_exceptions(exception_types = StandardError) ⇒ Object

Execute block, ignoring the specified exception type (default: all exceptions)



50
51
52
53
54
55
56
# File 'lib/rest-object/gree_err.rb', line 50

def self.with_ignored_exceptions(exception_types = StandardError)
    begin
        yield
    rescue exception_types => _the_exception
        # Ignore the exception
    end
end