Exception: Exception
- Defined in:
- lib/cosmos/core_ext/exception.rb,
lib/cosmos/io/json_rpc.rb
Overview
COSMOS specific additions to the Ruby Exception class
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
-
#formatted(hide_runtime_error_class = false, include_backtrace = true) ⇒ String
The formatted Exception.
-
#source ⇒ Array(String, Fixnum)
The filename and line number where the Exception occurred.
- #to_json(*a) ⇒ Object
Class Method Details
.from_hash(hash) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/cosmos/io/json_rpc.rb', line 123 def self.from_hash(hash) begin # Get Error class handling namespaced constants split_error_class_name = hash['class'].split("::") error_class = Object split_error_class_name.each do |name| error_class = error_class.const_get(name) end rescue error = Cosmos::JsonDRbUnknownError.new(hash['message']) error.set_backtrace(hash['backtrace'].concat(caller())) raise error end error = error_class.new(hash['message']) error.set_backtrace(hash['backtrace'].concat(caller())) if hash['backtrace'] hash['instance_variables'].each do |name, value| error.instance_variable_set(name.intern, value) end error end |
Instance Method Details
#as_json(*a) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cosmos/io/json_rpc.rb', line 106 def as_json(*a) hash = {} hash['class'] = self.class.name hash['message'] = self. hash['backtrace'] = self.backtrace instance_vars = {} self.instance_variables.each do |instance_var_name| instance_vars[instance_var_name.to_s] = self.instance_variable_get(instance_var_name.to_s.intern) end hash['instance_variables'] = instance_vars hash.as_json(*a) end |
#formatted(hide_runtime_error_class = false, include_backtrace = true) ⇒ String
Returns The formatted Exception.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cosmos/core_ext/exception.rb', line 19 def formatted(hide_runtime_error_class = false, include_backtrace = true) if include_backtrace and self.backtrace if hide_runtime_error_class and self.class == RuntimeError "#{self.}\n#{self.backtrace.join("\n")}" else "#{self.class.to_s.split('::')[-1]} : #{self.}\n#{self.backtrace.join("\n")}" end else if hide_runtime_error_class and self.class == RuntimeError "#{self.}" else "#{self.class.to_s.split('::')[-1]} : #{self.}" end end end |
#source ⇒ Array(String, Fixnum)
Returns The filename and line number where the Exception occurred.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cosmos/core_ext/exception.rb', line 37 def source trace = self.backtrace[0] split_trace = trace.split(':') filename = '' line_number = '' if trace[1..1] == ':' # Windows Path filename = split_trace[0] + ':' + split_trace[1] line_number = split_trace[2].to_i else filename = split_trace[0] line_number = split_trace[1].to_i end [filename, line_number] end |
#to_json(*a) ⇒ Object
119 120 121 |
# File 'lib/cosmos/io/json_rpc.rb', line 119 def to_json(*a) as_json(*a).to_json(*a) end |