Skip to content

Commit 8137ed0

Browse files
committed
Improve error message for clashing attributes and sub controllers
1 parent 9990065 commit 8137ed0

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/fastcs/controller.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ def _validate_io(self, ios: Sequence[AttributeIO[T, AttributeIORefT]]):
128128
def add_attribute(self, name, attribute: Attribute):
129129
if name in self.attributes and attribute is not self.attributes[name]:
130130
raise ValueError(
131-
f"Cannot add attribute {name}. "
132-
f"Controller {self} has has existing attribute {name}"
131+
f"Cannot add attribute {attribute}. "
132+
f"Controller {self} has has existing attribute {name}: "
133+
f"{self.attributes[name]}"
133134
)
134135
elif name in self.__sub_controller_tree.keys():
135136
raise ValueError(
136-
f"Cannot add attribute {name}. "
137-
f"Controller {self} has existing sub controller {name}"
137+
f"Cannot add attribute {attribute}. "
138+
f"Controller {self} has existing sub controller {name}: "
139+
f"{self.__sub_controller_tree[name]}"
138140
)
139141

140142
attribute.set_name(name)
@@ -145,13 +147,15 @@ def add_attribute(self, name, attribute: Attribute):
145147
def add_sub_controller(self, name: str, sub_controller: Controller):
146148
if name in self.__sub_controller_tree.keys():
147149
raise ValueError(
148-
f"Cannot add sub controller {name}. "
149-
f"Controller {self} has existing sub controller {name}"
150+
f"Cannot add sub controller {sub_controller}. "
151+
f"Controller {self} has existing sub controller {name}: "
152+
f"{self.__sub_controller_tree[name]}"
150153
)
151154
elif name in self.attributes:
152155
raise ValueError(
153-
f"Cannot add sub controller {name}. "
154-
f"Controller {self} has existing attribute {name}"
156+
f"Cannot add sub controller {sub_controller}. "
157+
f"Controller {self} has existing attribute {name}: "
158+
f"{self.attributes[name]}"
155159
)
156160

157161
sub_controller.set_path(self.path + [name])

0 commit comments

Comments
 (0)