Exception: Familia::RecordExistsError

Inherits:
NonUniqueKey show all
Defined in:
lib/familia/errors.rb

Overview

Raised when attempting to create an object that already exists in the database

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, existing_id: nil) ⇒ RecordExistsError

Returns a new instance of RecordExistsError.



294
295
296
297
298
# File 'lib/familia/errors.rb', line 294

def initialize(key, existing_id: nil)
  @existing_id = existing_id
  @key = key
  super(key)
end

Instance Attribute Details

#existing_id ⇒ Object (readonly)

Returns the value of attribute existing_id.



292
293
294
# File 'lib/familia/errors.rb', line 292

def existing_id
  @existing_id
end

#key ⇒ Object (readonly)

Returns the value of attribute key.



292
293
294
# File 'lib/familia/errors.rb', line 292

def key
  @key
end

Instance Method Details

#message ⇒ Object



300
301
302
303
304
305
306
307
308
309
# File 'lib/familia/errors.rb', line 300

def message
  msg = "Key already exists: #{key}"
  begin
    msg << " (existing_id=#{existing_id})" unless existing_id.nil?
  rescue StandardError
    # existing_id may not support nil?/to_s (e.g. a Redis::Future captured
    # inside a MULTI); a diagnostic message must never raise itself.
  end
  msg
end