Class: QRPC::Protocol::ExceptionData

Inherits:
JsonRpcObjects::Generic::Object
  • Object
show all
Defined in:
lib/qrpc/protocol/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::QrpcObject::VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Constructor.

Since:

  • 0.2.0



115
116
117
118
# File 'lib/qrpc/protocol/exception-data.rb', line 115

def initialize(data, mode = :encoded)
    @__encoded = (mode == :encoded)
    super(data)
end

Instance Attribute Details

#backtraceArray

Holds backtrace. See readme for structure details.

Since:

  • 0.2.0



53
54
55
# File 'lib/qrpc/protocol/exception-data.rb', line 53

def backtrace
  @backtrace
end

#dumpClass

Holds native dump. See readme for structure details.

Since:

  • 0.2.0



61
62
63
# File 'lib/qrpc/protocol/exception-data.rb', line 61

def dump
  @dump
end

#messageString

Holds exception message.

Since:

  • 0.2.0



45
46
47
# File 'lib/qrpc/protocol/exception-data.rb', line 45

def message
  @message
end

#nameSymbol

Holds exception name.

Since:

  • 0.2.0



37
38
39
# File 'lib/qrpc/protocol/exception-data.rb', line 37

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:

Since:

  • 0.2.0



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/qrpc/protocol/exception-data.rb', line 86

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



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/qrpc/protocol/exception-data.rb', line 124

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.

Since:

  • 0.2.0



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/qrpc/protocol/exception-data.rb', line 149

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