File: errors.rb

package info (click to toggle)
ruby-stomp 1.4.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 832 kB
  • sloc: ruby: 8,595; sh: 77; makefile: 3
file content (338 lines) | stat: -rw-r--r-- 9,679 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# -*- encoding: utf-8 -*-

module Stomp

  # Module level container for Stomp gem error classes.
  module Error

    # NoListenerGiven is raised if:
    # * No listener block is passed to Client#subscribe
    class NoListenerGiven < RuntimeError
      def message
        "No listener given"
      end
    end

    # DestinationRequired is raised if:
    # * No destination is passed to subscribe, unsubscribe, publish
    class DestinationRequired < RuntimeError
      def message
        "Destination required"
      end
    end

    # InvalidFormat is raised if:
    # * During frame parsing if a malformed frame is detected.
    class InvalidFormat < RuntimeError
      def message
        "Invalid message - invalid format"
      end
    end

    # InvalidServerCommand is raised if:
    # * An invalid STOMP COMMAND is received from the server.
    class InvalidServerCommand < RuntimeError
      def message
        "Invalid command from server"
      end
    end

    # InvalidMessageLength is raised if:
    # * An invalid message length is detected during a frame read.
    class InvalidMessageLength < RuntimeError
      def message
        "Invalid content length received"
      end
    end

    # PacketParsingTimeout is raised if:
    # * A frame read has started, but does not complete in 5 seconds.
    # * Use :parse_timeout connect parameter to override the timeout.
    class PacketParsingTimeout < RuntimeError
      def message
        "Packet parsing timeout"
      end
    end

    # ReceiveTimeout is raised if:
    # * The read socket shows "not ready" at any time after the timeout
    #   specified by :parse_timeout in the connection hash.
    class ReceiveTimeout < RuntimeError
      def message
        "Receive status timeout"
      end
    end

    # SocketOpenTimeout is raised if:
    # * A timeout occurs during a socket open.
    class SocketOpenTimeout < RuntimeError
      def message
        "Socket open timeout"
      end
    end

    # NoCurrentConnection is raised if:
    # * Any method is called when a current connection does not exist.
    # * And @closed_check is true (the default).
    class NoCurrentConnection < RuntimeError
      def message
        "no current connection exists"
      end
    end

    # MaxReconnectAttempts is raised if:
    # * The maximum number of retries has been reached for a reliable connection.
    class MaxReconnectAttempts < RuntimeError
      def message
        "Maximum number of reconnection attempts reached"
      end
    end

    # DuplicateSubscription is raised if:
    # * A duplicate subscription ID is detected in the current session.
    class DuplicateSubscription < RuntimeError
      def message
        "duplicate subscriptions are disallowed"
      end
    end

    # ProtocolErrorEmptyHeaderKey is raised if:
    # * Any header key is empty ("")
    class ProtocolErrorEmptyHeaderKey < RuntimeError
      def message
        "Empty header key"
      end
    end

    # ProtocolErrorEmptyHeaderValue is raised if:
    # * Any header value is empty ("") *and*
    # * Connection protocol level == 1.0
    class ProtocolErrorEmptyHeaderValue < RuntimeError
      def message
        "Empty header value, STOMP 1.0"
      end
    end

    # ProtocolError11p - base class of 1.1 CONNECT errors
    class ProtocolError11p < RuntimeError
      def message
        "STOMP 1.1+ CONNECT error"
      end
    end

    # ProtocolErrorConnect is raised if:
    # * Incomplete Stomp 1.1 headers are detected during a connect.
    class ProtocolErrorConnect < ProtocolError11p
      def message
        "STOMP 1.1+ CONNECT error, missing/incorrect CONNECT headers"
      end
    end

    # UnsupportedProtocolError is raised if:
    # * No supported Stomp protocol levels are detected during a connect.
    class UnsupportedProtocolError < ProtocolError11p
      def message
        "unsupported protocol level(s)"
      end
    end

    # InvalidHeartBeatHeaderError is raised if:
    # * A "heart-beat" header is present, but the values are malformed.
    class InvalidHeartBeatHeaderError < ProtocolError11p
      def message
        "heart-beat header value is malformed"
      end
    end

    # SubscriptionRequiredError is raised if:
    # * No subscription id is specified for a Stomp 1.1 subscribe.
    class SubscriptionRequiredError < RuntimeError
      def message
        "a valid subscription id header is required"
      end
    end

    # UTF8ValidationError is raised if:
    # * Stomp 1.1 headers are not valid UTF8.
    class UTF8ValidationError < RuntimeError
      def message
        "header is invalid UTF8"
      end
    end

    # MessageIDRequiredError is raised if:
    # * No messageid parameter is specified for ACK or NACK.
    class MessageIDRequiredError < RuntimeError
      def message
        "a valid message id is required for ACK/NACK"
      end
    end

    # SSLClientParamsError is raised if:
    # * Incomplete SSLParams are specified for an SSL connect.
    class SSLClientParamsError < RuntimeError
      def message
        "certificate and key files are both required"
      end
    end

    # StompServerError is raised if:
    # * Invalid (nil) data is received from the Stomp server.
    class StompServerError < RuntimeError
      def message
        "Connected, header read is nil, is this really a Stomp Server?"
      end
    end

    # ServerFrameNameError is raised if:
    # * Invalid frame is received from the Stomp server.
    class ServerFrameNameError < RuntimeError
      def initialize(bf)
        @bf = bf
      end
      def message
        "Connected, server frame name error: #{@bf.inspect}"
      end
    end

    # SSLNoKeyFileError is raised if:
    # * A supplied key file does not exist.
    class SSLNoKeyFileError < RuntimeError
      def message
        "client key file does not exist"
      end
    end

    # SSLUnreadableKeyFileError is raised if:
    # * A supplied key file is not readable.
    class SSLUnreadableKeyFileError < RuntimeError
      def message
        "client key file can not be read"
      end
    end

    # SSLNoCertFileError is raised if:
    # * A supplied SSL cert file does not exist.
    class SSLNoCertFileError < RuntimeError
      def message
        "client cert file does not exist"
      end
    end

    # SSLUnreadableCertFileError is raised if:
    # * A supplied SSL cert file is not readable.
    class SSLUnreadableCertFileError < RuntimeError
      def message
        "client cert file can not be read"
      end
    end

    # SSLNoTruststoreFileError is raised if:
    # * A supplied SSL trust store file does not exist.
    class SSLNoTruststoreFileError < RuntimeError
      def message
        "a client truststore file does not exist"
      end
    end

    # SSLUnreadableTruststoreFileError is raised if:
    # * A supplied SSL trust store file is not readable.
    class SSLUnreadableTruststoreFileError < RuntimeError
      def message
        "a client truststore file can not be read"
      end
    end

    # LoggerConnectionError is not raised by the gem.  It may be
    # raised by client logic in callback logger methods to signal
    # that a connection should not proceed.
    class LoggerConnectionError < RuntimeError
    end

    # NilMessageError is raised if:
    # * Invalid (nil) data is received from the Stomp server in a client's
    # listener thread, and the connection is not reliable.
    class NilMessageError < RuntimeError
      def message
        "Received message is nil, and connection not reliable"
      end
    end

    # MalformedFailoverOptionsError is raised if failover URL
    # options can not be parsed
    class MalformedFailoverOptionsError < RuntimeError
      def message
        "failover options are malformed"
      end
    end

    # ConnectReadTimeout is raised if:
    # * A read for CONNECTED/ERROR is untimely
    class ConnectReadTimeout < RuntimeError
      def message
        "Connect read for CONNECTED/ERROR timeout"
      end
    end

    class StompException < RuntimeError; end

    class BrokerException < StompException
      attr_reader :headers, :message, :receipt_id, :broker_backtrace

      def initialize(message)
        @message          = message.headers.delete('message')
        @receipt_id       = message.headers.delete('receipt-id') || 'no receipt id'
        @headers          = message.headers
        @broker_backtrace = message.body
      end
    end

    class ProducerFlowControlException < BrokerException
      attr_reader :producer_id, :dest_name

      def initialize(message)
        super(message)
        msg_headers = /.*producer\s+\((.*)\).*to\s+prevent\s+flooding\s+([^\s]*)\.\s+/i.match(@message)

        @producer_id = msg_headers && msg_headers[1]
        @dest_name   = msg_headers && msg_headers[2]
      end
    end

    class ProtocolException < BrokerException
      def initialize(message)
        super(message)
      end
    end

    class StartTimeoutException < StompException
      def initialize(timeout)
        @timeout = timeout
      end

      def message
        "Client failed to start in #{@timeout} seconds"
      end
    end

    class ReadReceiptTimeoutException < StompException
      def initialize(timeout)
        @timeout = timeout
      end

      def message
        "Read receipt not received after #{@timeout} seconds"
      end
    end

    # HandShakeDetectedError is raised if:
    # * A normal read detects inbound handskake data
    class HandShakeDetectedError < RuntimeError
      def message
        "Handshake data found, possible mismatched port and sslparams"
      end
    end

  end # module Error

end # module Stomp