Class: QRPC::Protocol::JsonRpc::Native::ExceptionData
- Inherits:
-
JsonRpcObjects::Generic::Object
- Object
- JsonRpcObjects::Generic::Object
- QRPC::Protocol::JsonRpc::Native::ExceptionData
- Defined in:
- lib/qrpc/protocol/json-rpc/native/exception-data.rb
Overview
Exception data QRPC JSON-RPC object.
Constant Summary collapse
Instance Attribute Summary collapse
-
#backtrace ⇒ Array
Holds backtrace.
-
#dump ⇒ Class
Holds native dump.
-
#message ⇒ String
Holds exception message.
-
#name ⇒ Symbol
Holds exception name.
Class Method Summary collapse
-
.create(arg1, message = nil, opts = { }) ⇒ QRPC::Protocol::ExceptionData
Creates new QRPC JSON-RPC object.
Instance Method Summary collapse
-
#check! ⇒ Object
Checks correctness of the object data.
-
#initialize(data, mode = :encoded) ⇒ ExceptionData
constructor
Constructor.
-
#output ⇒ Hash
Renders data to output form.
Constructor Details
#initialize(data, mode = :encoded) ⇒ ExceptionData
Constructor.
133 134 135 136 |
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 133 def initialize(data, mode = :encoded) @__encoded = (mode == :encoded) super(data) end |
Instance Attribute Details
#backtrace ⇒ Array
Holds backtrace. See readme for structure details.
71 72 73 |
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 71 def backtrace @backtrace end |
#dump ⇒ Class
Holds native dump. See readme for structure details.
79 80 81 |
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 79 def dump @dump end |
#message ⇒ String
Holds exception message.
63 64 65 |
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 63 def @message end |
#name ⇒ Symbol
Holds exception name.
55 56 57 |
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 55 def name @name end |
Class Method Details
.create(exception, nil, opts = { }) ⇒ QRPC::Protocol::ExceptionData .create(name, message, opts = { }) ⇒ QRPC::Protocol::ExceptionData
Creates new QRPC JSON-RPC object.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 104 def self.create(arg1, = nil, opts = { }) if arg1.kind_of? ::Exception mode = :decoded data = { :name => arg1.class.name, :message => arg1., :backtrace => arg1.backtrace, :dump => { "format" => "ruby", "object" => arg1 } } else mode = :encoded data = { :name => arg1, :message => } end data.merge! opts return self::new(data, mode) end |
Instance Method Details
#check! ⇒ Object
Checks correctness of the object data.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 142 def check! self.normalize! if not @name.kind_of? Symbol raise Exception::new("Exception name is expected to be Symbol or convertable to symbol.") end if not @backtrace.nil? and not @backtrace.kind_of? Array raise Exception::new("Backtrace is expected to be an Array.") end if not @dump.nil? if @dump.object.nil? and @dump.raw.nil? raise Exception::new("Either object or RAW form of the dump must be set if dump is set.") elsif @dump.format.nil? or not @dump.format.kind_of? Symbol raise Exception::new("Dump format must be set and must be Symbol.") end end end |
#output ⇒ Hash
Renders data to output form.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 167 def output result = { "name" => @name.to_s, "message" => @message, } # Backtrace if @backtrace.kind_of? Array result["backtrace"] = @backtrace.map { |i| Base64.encode64(i) } end # Dump if not @dump.nil? result["dump"] = { "format" => @dump.format, } if not dump.object.nil? raw = Base64.encode64(Marshal.dump(dump.object)) else raw = dump.raw end result["dump"]["raw"] = raw end return result end |