Exception: Moxml::ValidationError

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

Overview

Error raised when XML validation fails

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, node: nil, constraint: nil, value: nil) ⇒ ValidationError

Returns a new instance of ValidationError.



53
54
55
56
57
58
# File 'lib/moxml/error.rb', line 53

def initialize(message, node: nil, constraint: nil, value: nil)
  @node = node
  @constraint = constraint
  @value = value
  super(message)
end

Instance Attribute Details

#constraintObject (readonly)

Returns the value of attribute constraint.



51
52
53
# File 'lib/moxml/error.rb', line 51

def constraint
  @constraint
end

#nodeObject (readonly)

Returns the value of attribute node.



51
52
53
# File 'lib/moxml/error.rb', line 51

def node
  @node
end

#valueObject (readonly)

Returns the value of attribute value.



51
52
53
# File 'lib/moxml/error.rb', line 51

def value
  @value
end

Instance Method Details

#to_sObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/moxml/error.rb', line 60

def to_s
  msg = super
  # Only add extra details if any were provided
  has_details = (@node.is_a?(Element) || @node.is_a?(Attribute)) || @constraint || @value
  if has_details
    msg += "\n  Node: <#{@node.name}>" if @node.is_a?(Element) || @node.is_a?(Attribute)
    msg += "\n  Constraint: #{@constraint}" if @constraint
    msg += "\n  Value: #{@value.inspect}" if @value
    msg += "\n  Hint: Ensure the value meets XML specification requirements"
  end
  msg
end