Exception: Synthra::Errors::FieldOrderError

Inherits:
ParseError show all
Defined in:
lib/synthra/errors.rb

Overview

Field order error for copy() references

Raised when a copy() field references another field that is defined after it in the schema. Since fields are generated in definition order, this would result in nil values.

Examples:

Field order problem

# Order:
#   user_id: copy("user.id")  <- ERROR: user not defined yet!
#   user: User

Constant Summary collapse

ERROR_CODE =
"FIELD_ORDER_ERROR"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_name:, copy_path:, schema_name:, suggestion: nil, **kwargs) ⇒ FieldOrderError

Create a new FieldOrderError

Parameters:

  • field_name (String)

    the copy field name

  • copy_path (String)

    the path being copied

  • schema_name (String)

    the schema name

  • suggestion (String) (defaults to: nil)

    how to fix the error

  • kwargs (Hash)

    additional options



378
379
380
381
382
383
384
385
386
387
# File 'lib/synthra/errors.rb', line 378

def initialize(field_name:, copy_path:, schema_name:, suggestion: nil, **kwargs)
  @field_name = field_name
  @copy_path = copy_path
  @schema_name = schema_name

  message = "Field order error in '#{schema_name}': " \
            "'#{field_name}' uses copy(\"#{copy_path}\") but the source field is defined after it"
  
  super(message, suggestions: suggestion ? [suggestion] : nil, **kwargs)
end

Instance Attribute Details

#copy_pathString (readonly)

Returns the path being copied.

Returns:

  • (String)

    the path being copied



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/synthra/errors.rb', line 364

class FieldOrderError < ParseError
  ERROR_CODE = "FIELD_ORDER_ERROR"
  attr_reader :field_name, :copy_path, :schema_name


  # Create a new FieldOrderError
  #
  # @param field_name [String] the copy field name
  # @param copy_path [String] the path being copied
  # @param schema_name [String] the schema name
  # @param suggestion [String] how to fix the error
  # @param kwargs [Hash] additional options
  #

  def initialize(field_name:, copy_path:, schema_name:, suggestion: nil, **kwargs)
    @field_name = field_name
    @copy_path = copy_path
    @schema_name = schema_name

    message = "Field order error in '#{schema_name}': " \
              "'#{field_name}' uses copy(\"#{copy_path}\") but the source field is defined after it"
    
    super(message, suggestions: suggestion ? [suggestion] : nil, **kwargs)
  end
end

#field_nameString (readonly)

Returns the name of the copy field.

Returns:

  • (String)

    the name of the copy field



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/synthra/errors.rb', line 364

class FieldOrderError < ParseError
  ERROR_CODE = "FIELD_ORDER_ERROR"
  attr_reader :field_name, :copy_path, :schema_name


  # Create a new FieldOrderError
  #
  # @param field_name [String] the copy field name
  # @param copy_path [String] the path being copied
  # @param schema_name [String] the schema name
  # @param suggestion [String] how to fix the error
  # @param kwargs [Hash] additional options
  #

  def initialize(field_name:, copy_path:, schema_name:, suggestion: nil, **kwargs)
    @field_name = field_name
    @copy_path = copy_path
    @schema_name = schema_name

    message = "Field order error in '#{schema_name}': " \
              "'#{field_name}' uses copy(\"#{copy_path}\") but the source field is defined after it"
    
    super(message, suggestions: suggestion ? [suggestion] : nil, **kwargs)
  end
end

#schema_nameString (readonly)

Returns the schema containing the error.

Returns:

  • (String)

    the schema containing the error



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/synthra/errors.rb', line 364

class FieldOrderError < ParseError
  ERROR_CODE = "FIELD_ORDER_ERROR"
  attr_reader :field_name, :copy_path, :schema_name


  # Create a new FieldOrderError
  #
  # @param field_name [String] the copy field name
  # @param copy_path [String] the path being copied
  # @param schema_name [String] the schema name
  # @param suggestion [String] how to fix the error
  # @param kwargs [Hash] additional options
  #

  def initialize(field_name:, copy_path:, schema_name:, suggestion: nil, **kwargs)
    @field_name = field_name
    @copy_path = copy_path
    @schema_name = schema_name

    message = "Field order error in '#{schema_name}': " \
              "'#{field_name}' uses copy(\"#{copy_path}\") but the source field is defined after it"
    
    super(message, suggestions: suggestion ? [suggestion] : nil, **kwargs)
  end
end