Exception: KStor::Error
- Inherits:
-
StandardError
- Object
- StandardError
- KStor::Error
- Defined in:
- lib/kstor/error.rb
Overview
Base class of KStor errors.
Each subclass declares a code and is stored in a global registry.
Direct Known Subclasses
CantOpenDatabase, CryptoError, InvalidMessage, InvalidSession, MissingArgument, MissingLoginPassword, RbNaClError, SecretNotFound, UnknownRequestType, UserNotAllowed
Class Attribute Summary collapse
-
.code ⇒ Object
readonly
Returns the value of attribute code.
-
.message ⇒ Object
readonly
Returns the value of attribute message.
-
.registry ⇒ Object
readonly
Returns the value of attribute registry.
Class Method Summary collapse
- .error_code(str) ⇒ Object
- .error_message(str) ⇒ Object
- .for_code(code, *args) ⇒ Object
- .inherited(subclass) ⇒ Object
- .list ⇒ Object
Instance Method Summary collapse
-
#initialize(*args) ⇒ Error
constructor
A new instance of Error.
- #response ⇒ Object
Constructor Details
#initialize(*args) ⇒ Error
Returns a new instance of Error.
46 47 48 |
# File 'lib/kstor/error.rb', line 46 def initialize(*args) super(format("ERR/%s #{self.class.}", self.class.code, *args)) end |
Class Attribute Details
.code ⇒ Object (readonly)
Returns the value of attribute code.
11 12 13 |
# File 'lib/kstor/error.rb', line 11 def code @code end |
.message ⇒ Object (readonly)
Returns the value of attribute message.
12 13 14 |
# File 'lib/kstor/error.rb', line 12 def @message end |
.registry ⇒ Object (readonly)
Returns the value of attribute registry.
13 14 15 |
# File 'lib/kstor/error.rb', line 13 def registry @registry end |
Class Method Details
.error_code(str) ⇒ Object
15 16 17 |
# File 'lib/kstor/error.rb', line 15 def error_code(str) @code = str end |
.error_message(str) ⇒ Object
19 20 21 |
# File 'lib/kstor/error.rb', line 19 def (str) @message = str end |
.for_code(code, *args) ⇒ Object
23 24 25 |
# File 'lib/kstor/error.rb', line 23 def for_code(code, *args) @registry[code].new(*args) end |
.inherited(subclass) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kstor/error.rb', line 32 def self.inherited(subclass) super Log.debug("#{subclass} inherits from Error") @registry ||= ErrorRegistry.new if @registry.key?(subclass.code) code = subclass.code klass = @registry[code] raise "duplicate error code #{code} in #{subclass}, " \ "already defined in #{klass}" end @registry << subclass end |
.list ⇒ Object
27 28 29 |
# File 'lib/kstor/error.rb', line 27 def list @registry.classes end |