I'm wondering whether conditions could be fleshed out some more or if I'm
missing some intention/design…
I was employing a technique described by Ramon Leon  for conditions that
affect multiple descriptions, namely:
addCondition: [:memento |
(memento cache at: self descriptionEndDate) > (memento cache at:
labelled: 'End date must be after start date';
I noticed a few seeming limitations of this technique (and conditions in
1. The example above only works when using a cached memento. It fails due to
DNU #cache for other Memento types, as well as when validating objects
directly (e.g. `myDomainObject magritteDescription validate: self.`)
2. When the above fails, the exception bubbles up on its own instead of
being grouped together with failed conditions from individual descriptions
because `MAValidatorVisitor>>#visitContainer:` handles the container
validation separately (via `super visitContainer: aDescription.`) before
looping through the element descriptions to validate them.
3. In both the container and element validations, once one condition
per-[container | element] fails, others are not processed (for the same
[container | element]). I experimented with expanding the error handling
block, but couldn't see a great way to overcome this without a more
significant rewrite because MAValidationErrors are not resumable.
My quick fix idea would be to make MAValidationErrors resumable and expand
the error block to include the container along with the element validations.
Would that be the best way to address the issues above?
Sean P. DeNigris wrote
> 1. The example above only works when using a cached memento. It fails due
> DNU #cache for other Memento types, as well as when validating objects
> directly (e.g. `myDomainObject magritteDescription validate: self.`)
This one was actually a bug/limitation in the example code. Replacing `cache
at:` with `readUsing:`, which is polymorphic among all Memento types and
Object, solves the problem.
Stephan Eggermont-3 wrote
> yes, some more involved surgery seems needed
All points in the OP are fixed . It's hard to show #2 in a script, but
this illustrates #3:
desc := MADurationDescription new
addCondition: [ :d | d hours = d minutes ];
addCondition: [ :d | d hours = d days ];
duration := '1:02:03:04' asDuration.
desc validate: duration. "Returns a MAMultipleErrors with both failed
conditions instead of stopping validation after the first failure"