Skip to content

Commit

Permalink
improve an error when children have a parent
Browse files Browse the repository at this point in the history
  • Loading branch information
syrel committed Mar 27, 2024
1 parent ab794e4 commit 5fe0343
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Bloc/BlAlreadyAddedAsChildError.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
#instVars : [
'element'
],
#category : 'Bloc-Basic-Errors'
#category : #'Bloc-Basic-Errors'
}

{ #category : #'instance creation' }
Expand All @@ -18,7 +18,7 @@ BlAlreadyAddedAsChildError class >> element: anElement [

{ #category : #accessing }
BlAlreadyAddedAsChildError >> description [
^ 'Can not add child that is already added to another element!'
^ ('Can not add {1} because it is already added to another element.') format: { self element }
]

{ #category : #accessing }
Expand Down
7 changes: 4 additions & 3 deletions src/Bloc/BlElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ BlElement >> addChildren: aListOfElements [
self
assert: [ aListOfElements isNotNil ]
description: [ 'List of elements to add must not be nil' ].
self
assert: [ aListOfElements allSatisfy: [ :anElement | anElement parent isNil ] ]
description: [ 'All elements must not have parent' ].

aListOfElements do: [ :eachElement |
eachElement hasParent
ifTrue: [ (BlAlreadyAddedAsChildError element: eachElement) signal ] ].

"fast exit if there are no elements to add"
aListOfElements
Expand Down

0 comments on commit 5fe0343

Please sign in to comment.