Exception: Synthra::Errors::UniquenessError
- Inherits:
-
GenerationError
- Object
- StandardError
- Error
- GenerationError
- Synthra::Errors::UniquenessError
- Defined in:
- lib/synthra/errors.rb
Overview
Uniqueness constraint could not be satisfied
Raised when the generator cannot produce a unique value after multiple attempts. This typically happens when generating many records with unique fields that have limited possible values.
Constant Summary collapse
- ERROR_CODE =
"UNIQUENESS_ERROR"
Instance Attribute Summary collapse
-
#attempts ⇒ Integer
readonly
Number of attempts made before giving up.
-
#field ⇒ String
readonly
The field name that requires uniqueness.
-
#last_values ⇒ Array
readonly
The last few values that were rejected as duplicates.
-
#schema_name ⇒ Object
readonly
Returns the value of attribute schema_name.
Instance Method Summary collapse
-
#initialize(field:, attempts: nil, last_values: nil, schema_name: nil) ⇒ UniquenessError
constructor
Create a new UniquenessError.
Constructor Details
#initialize(field:, attempts: nil, last_values: nil, schema_name: nil) ⇒ UniquenessError
Create a new UniquenessError
639 640 641 642 643 644 645 646 647 648 649 |
# File 'lib/synthra/errors.rb', line 639 def initialize(field:, attempts: nil, last_values: nil, schema_name: nil) @field = field @attempts = attempts || Synthra.configuration.max_unique_retries @last_values = last_values || [] @schema_name = schema_name = "Could not generate unique value for '#{field}'" += " in schema '#{schema_name}'" if schema_name += " after #{@attempts} attempts" += ". Last values: #{@last_values.first(5).inspect}" unless @last_values.empty? super() end |
Instance Attribute Details
#attempts ⇒ Integer (readonly)
Returns number of attempts made before giving up.
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/synthra/errors.rb', line 626 class UniquenessError < GenerationError ERROR_CODE = "UNIQUENESS_ERROR" attr_reader :field, :attempts, :last_values, :schema_name # Create a new UniquenessError # # @param field [String] the field name that requires uniqueness # @param attempts [Integer] number of generation attempts made # @param last_values [Array] the last values attempted (for debugging) # @param schema_name [String, nil] the schema name where the error occurred # def initialize(field:, attempts: nil, last_values: nil, schema_name: nil) @field = field @attempts = attempts || Synthra.configuration.max_unique_retries @last_values = last_values || [] @schema_name = schema_name = "Could not generate unique value for '#{field}'" += " in schema '#{schema_name}'" if schema_name += " after #{@attempts} attempts" += ". Last values: #{@last_values.first(5).inspect}" unless @last_values.empty? super() end end |
#field ⇒ String (readonly)
Returns the field name that requires uniqueness.
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/synthra/errors.rb', line 626 class UniquenessError < GenerationError ERROR_CODE = "UNIQUENESS_ERROR" attr_reader :field, :attempts, :last_values, :schema_name # Create a new UniquenessError # # @param field [String] the field name that requires uniqueness # @param attempts [Integer] number of generation attempts made # @param last_values [Array] the last values attempted (for debugging) # @param schema_name [String, nil] the schema name where the error occurred # def initialize(field:, attempts: nil, last_values: nil, schema_name: nil) @field = field @attempts = attempts || Synthra.configuration.max_unique_retries @last_values = last_values || [] @schema_name = schema_name = "Could not generate unique value for '#{field}'" += " in schema '#{schema_name}'" if schema_name += " after #{@attempts} attempts" += ". Last values: #{@last_values.first(5).inspect}" unless @last_values.empty? super() end end |
#last_values ⇒ Array (readonly)
Returns the last few values that were rejected as duplicates.
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/synthra/errors.rb', line 626 class UniquenessError < GenerationError ERROR_CODE = "UNIQUENESS_ERROR" attr_reader :field, :attempts, :last_values, :schema_name # Create a new UniquenessError # # @param field [String] the field name that requires uniqueness # @param attempts [Integer] number of generation attempts made # @param last_values [Array] the last values attempted (for debugging) # @param schema_name [String, nil] the schema name where the error occurred # def initialize(field:, attempts: nil, last_values: nil, schema_name: nil) @field = field @attempts = attempts || Synthra.configuration.max_unique_retries @last_values = last_values || [] @schema_name = schema_name = "Could not generate unique value for '#{field}'" += " in schema '#{schema_name}'" if schema_name += " after #{@attempts} attempts" += ". Last values: #{@last_values.first(5).inspect}" unless @last_values.empty? super() end end |
#schema_name ⇒ Object (readonly)
Returns the value of attribute schema_name.
628 629 630 |
# File 'lib/synthra/errors.rb', line 628 def schema_name @schema_name end |