Exception: Axn::ValidationError
- Inherits:
-
ContractViolation
- Object
- StandardError
- ContractViolation
- Axn::ValidationError
- Defined in:
- lib/axn/exceptions.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#user_facing_message ⇒ Object
readonly
Returns the value of attribute user_facing_message.
Class Method Summary collapse
-
.user_facing?(exception) ⇒ Boolean
Single source of truth for "did this (arbitrary) exception settle into the user-facing failure bucket?" — folds in the
is_a?guard so the Executor (classification) and Result (outcome + surfaced reason) ask the question one way and can't drift apart.
Instance Method Summary collapse
-
#__present_as(string) ⇒ Object
Normalized on assignment and read back plain, on the same terms as
Axn::Failure#__present_asabove: what resolution produces can be the caller's own object, andpresencedispatched itsblank?from inside the path settling the failure. -
#field_errors ⇒ Object
Structured per-field view of the validation errors, for callers that want to format each failure individually (e.g. a tool adapter handing per-argument reasons back to a model).
-
#initialize(errors, user_facing: false, user_facing_message: nil) ⇒ ValidationError
constructor
user_facing:marks an inbound validation failure that the Executor has reclassified into the failure bucket (seeexpects ..., user_facing:). - #message ⇒ Object
- #to_s ⇒ Object
- #user_facing? ⇒ Boolean
Constructor Details
#initialize(errors, user_facing: false, user_facing_message: nil) ⇒ ValidationError
user_facing: marks an inbound validation failure that the Executor has reclassified into the
failure bucket (see expects ..., user_facing:). The structured errors are preserved on the
exception either way; user_facing_message carries the (possibly overridden) message that
surfaces on result.error as an attachable reason — headlined by a declared base error just
like a fail! reason — leaving the dev-facing #message (full validation errors) intact.
317 318 319 320 321 322 323 |
# File 'lib/axn/exceptions.rb', line 317 def initialize(errors, user_facing: false, user_facing_message: nil) @errors = errors @user_facing = user_facing @user_facing_message = @presentation = nil # set by __present_as when an owned, user-facing failure is stamped (see Axn::Failure) super(errors) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
310 311 312 |
# File 'lib/axn/exceptions.rb', line 310 def errors @errors end |
#user_facing_message ⇒ Object (readonly)
Returns the value of attribute user_facing_message.
310 311 312 |
# File 'lib/axn/exceptions.rb', line 310 def @user_facing_message end |
Class Method Details
.user_facing?(exception) ⇒ Boolean
Single source of truth for "did this (arbitrary) exception settle into the user-facing failure
bucket?" — folds in the is_a? guard so the Executor (classification) and Result (outcome +
surfaced reason) ask the question one way and can't drift apart.
328 |
# File 'lib/axn/exceptions.rb', line 328 def self.user_facing?(exception) = exception.is_a?(self) && exception.user_facing? |
Instance Method Details
#__present_as(string) ⇒ Object
Normalized on assignment and read back plain, on the same terms as Axn::Failure#__present_as above:
what resolution produces can be the caller's own object, and presence dispatched its blank? from
inside the path settling the failure.
335 |
# File 'lib/axn/exceptions.rb', line 335 def __present_as(string) = @presentation = Axn::Internal::NativeMethods.absent_value?(string) ? nil : string |
#field_errors ⇒ Object
Structured per-field view of the validation errors, for callers that want to format each
failure individually (e.g. a tool adapter handing per-argument reasons back to a model).
full_message so each entry reads standalone; base-level errors surface with field == :base.
342 |
# File 'lib/axn/exceptions.rb', line 342 def field_errors = errors.map { |error| { field: error.attribute, message: error. } } |
#message ⇒ Object
336 |
# File 'lib/axn/exceptions.rb', line 336 def = @presentation || errors..to_sentence |
#to_s ⇒ Object
337 |
# File 'lib/axn/exceptions.rb', line 337 def to_s = |
#user_facing? ⇒ Boolean
330 |
# File 'lib/axn/exceptions.rb', line 330 def user_facing? = @user_facing |