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
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/cosmos/io/json_rpc.rb', line 151 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
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/cosmos/io/json_rpc.rb', line 134 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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cosmos/core_ext/exception.rb', line 28 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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cosmos/core_ext/exception.rb', line 46 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
147 148 149 |
# File 'lib/cosmos/io/json_rpc.rb', line 147 def to_json(*a) as_json(*a).to_json(*a) end |