Class: QRPC::Protocol::JsonRpc::Native::ExceptionData

Inherits:
JsonRpcObjects::Generic::Object
  • Object
show all
Defined in:
lib/qrpc/protocol/json-rpc/native/exception-data.rb

Overview

Exception data QRPC JSON-RPC object.

Since:

  • 0.2.0

Constant Summary collapse

VERSION =

Holds JSON-RPC version indication.

Since:

  • 0.2.0

QRPC::Protocol::JsonRpc::Native::QrpcObject::VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, mode = :encoded) ⇒ ExceptionData

Constructor.

Parameters:

  • data (Hash)

    for initializing the object

Since:

  • 0.2.0



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

#backtraceArray

Holds backtrace. See readme for structure details.

Returns:

  • (Array)

Since:

  • 0.2.0



71
72
73
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 71

def backtrace
  @backtrace
end

#dumpClass

Holds native dump. See readme for structure details.

Returns:

  • (Class)

Since:

  • 0.2.0



79
80
81
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 79

def dump
  @dump
end

#messageString

Holds exception message.

Returns:

  • (String)

Since:

  • 0.2.0



63
64
65
# File 'lib/qrpc/protocol/json-rpc/native/exception-data.rb', line 63

def message
  @message
end

#nameSymbol

Holds exception name.

Returns:

  • (Symbol)

Since:

  • 0.2.0



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.

Overloads:

  • .create(exception, nil, opts = { }) ⇒ QRPC::Protocol::ExceptionData

    Creates from exception.

    Parameters:

    • exception (Exception)

      exception object

    • nil (NilClass)

      (not applicable)

    • opts (Hash) (defaults to: { })

      optional members of object

  • .create(name, message, opts = { }) ⇒ QRPC::Protocol::ExceptionData

    Creates from exception description.

    Parameters:

    • name (Symbol, String)

      exception name

    • exception (Object)

      message

    • opts (Hash) (defaults to: { })

      optional members of object

Returns:

  • (QRPC::Protocol::ExceptionData)

    new instance

Since:

  • 0.2.0



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, message = nil, opts = { })
    if arg1.kind_of? ::Exception
        mode = :decoded
        data = {
            :name => arg1.class.name,
            :message => arg1.message,
            :backtrace => arg1.backtrace,
            :dump => {
                "format" => "ruby",
                "object" => arg1
            }
        }
    else
        mode = :encoded
        data = {
            :name => arg1,
            :message => message
        }
    end
    
    data.merge! opts
    return self::new(data, mode)
end

Instance Method Details

#check!Object

Checks correctness of the object data.

Since:

  • 0.2.0



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

#outputHash

Renders data to output form.

Returns:

  • (Hash)

    with data of object

Since:

  • 0.2.0



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