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, MissingLoginPassword, MissingMessageArgument, 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
Declare error code for a subclass.
-
.error_message(str) ⇒ Object
Declare error message for a subclass.
-
.for_code(code, *args) ⇒ Object
Create a new error for this code.
-
.inherited(subclass) ⇒ Object
When subclassed, add child to registry.
-
.list ⇒ Object
List of all subclasses.
Instance Method Summary collapse
-
#initialize(*args) ⇒ KStor::Error
constructor
Create new error.
-
#response(sid) ⇒ KStor::Message::Error
Create a new server response from an error.
Constructor Details
#initialize(*args) ⇒ KStor::Error
Create new error.
66 67 68 |
# File 'lib/kstor/error.rb', line 66 def initialize(*args) super(format("ERR/%s #{self.class.message}", 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 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
Declare error code for a subclass.
18 19 20 |
# File 'lib/kstor/error.rb', line 18 def error_code(str) @code = str end |
.error_message(str) ⇒ Object
Declare error message for a subclass.
This will be passed to String#format as a format string.
27 28 29 |
# File 'lib/kstor/error.rb', line 27 def (str) = str end |
.for_code(code, *args) ⇒ Object
Create a new error for this code.
35 36 37 |
# File 'lib/kstor/error.rb', line 35 def for_code(code, *args) @registry[code].new(*args) end |
.inherited(subclass) ⇒ Object
When subclassed, add child to registry.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kstor/error.rb', line 48 def self.inherited(subclass) super @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
List of all subclasses.
40 41 42 |
# File 'lib/kstor/error.rb', line 40 def list @registry.classes end |
Instance Method Details
#response(sid) ⇒ KStor::Message::Error
Create a new server response from an error.
73 74 75 76 77 78 |
# File 'lib/kstor/error.rb', line 73 def response(sid) Message::Error.new( { 'code' => self.class.code, 'message' => }, { session_id: sid } ) end |