Exception: Castkit::AttributeError

Inherits:
Error
  • Object
show all
Defined in:
lib/castkit/error.rb

Overview

Raised for attribute validation, access, or casting failures.

Instance Attribute Summary

Attributes inherited from Error

#context

Instance Method Summary collapse

Methods inherited from Error

#initialize

Constructor Details

This class inherits a constructor from Castkit::Error

Instance Method Details

#fieldSymbol

Returns the field name related to the error, if available.

Returns:

  • (Symbol)


27
28
29
# File 'lib/castkit/error.rb', line 27

def field
  context.is_a?(Hash) ? context[:field] : context || :unknown
end

#to_sString

Formats the error message with field info if available.

Returns:

  • (String)


34
35
36
37
# File 'lib/castkit/error.rb', line 34

def to_s
  field_info = field ? " (on #{field})" : ""
  "#{super}#{field_info}"
end