Eno::Field » #error

error → Eno::ValidationError
error(message) → Eno::ValidationError
error(message_proc) → Eno::ValidationError
error { |name, value| message_block } → Eno::ValidationError

Generate an error in the context of the element. The error includes a generic message by default, or a custom one if you supply it (which is the recommended practice). You can also pass a message Proc or block which (like loaders too) gets the name and value as arguments and returns a message string. This serves to create highly informative error messages that pin-point to the exact origin of the error, even when the initial reading of data is already past, e.g. when the error condition is only apparent later, when more processing has occurred or other data is available.

enocolor: cozy
rubydocument = Eno.parse(input)
element, value = document.field('color', with_element: true)

# ...

if value == 'cozy'
  raise element.error('Postprocessing determined that "cozy" is not a color after all.')
end

Parameters

message, message_block or message_proc

Highly recommended to provide one (but it's optional).Either directly pass a string, or alternatively a Proc or block returning a string.(The Proc or block is passed name and value as arguments, and if both a Proc and blockare supplied the block has higher precedence.)

Return value

An Eno::ValidationError in the context of the element's value(and with an optional custom message).