Skip to content

Commit

Permalink
Merge pull request #350 from seandenigris/clean_validator-visitor-visit
Browse files Browse the repository at this point in the history
[Clean]: Validation Error Catching should be in Validator Visitor
  • Loading branch information
seandenigris authored Feb 29, 2024
2 parents 192ecbc + d418ca8 commit d62e8e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
19 changes: 17 additions & 2 deletions source/Magritte-Model/MAValidatorVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,24 @@ MAValidatorVisitor >> validate: anObject using: aDescription [
MAValidatorVisitor >> visit: aDescription [
"Only visit objects that are visible and that can be changed."

| errors |
(aDescription isVisible and: [ aDescription isReadOnly not ])
ifTrue: [ super visit: aDescription ].

ifFalse: [ ^ self ].

errors := OrderedCollection new.
[
super visit: aDescription
]
on: MAValidationError
do: [ :err |
errors add: err.
err resume ].

errors isEmpty ifFalse: [
MAMultipleErrors
description: aDescription
errors: errors
signal: aDescription label ]
]

{ #category : #'visiting-descriptions' }
Expand Down
17 changes: 2 additions & 15 deletions source/Magritte-Model/MAVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,8 @@ MAVisitor class >> buildVisitorHierarchyForClass: aClass selector: aBlock classi
{ #category : #visiting }
MAVisitor >> visit: anObject [
"Visit ==anObject== with the receiving visitor."
| errors |
errors := OrderedCollection new.
[
anObject acceptMagritte: self.
]
on: MAValidationError
do: [ :err |
errors add: err.
err resume ].

errors isEmpty ifFalse: [
MAMultipleErrors
description: anObject
errors: errors
signal: anObject label ]

anObject acceptMagritte: self.
]

{ #category : #visiting }
Expand Down

0 comments on commit d62e8e8

Please sign in to comment.