Skip to content

Commit bd3735f

Browse files
committed
fix: minor changes to opossum_model.py
* default to treating a Resource as file if the type is undefined and no children present * provide slightly more information in an error message
1 parent 41625aa commit bd3735f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/opossum_lib/opossum_model.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ class Resource(BaseModel):
135135
children: dict[str, Resource] = {}
136136

137137
def to_opossum_file_format(self) -> opossum_file.ResourceInFile:
138-
if self.type == ResourceType.FILE:
139-
return 1
140-
else:
138+
if self.children or self.type == ResourceType.FOLDER:
141139
return {
142140
str(child.path.relative_to(self.path)).replace(
143141
"\\", "/"
144142
): child.to_opossum_file_format()
145143
for child in self.children.values()
146144
}
145+
else:
146+
return 1
147147

148148
def add_resource(self, resource: Resource) -> None:
149149
if not resource.path.is_relative_to(self.path):
@@ -174,7 +174,10 @@ def _update(self, other: Resource) -> None:
174174
+ f"{self.path} vs. {other.path}"
175175
)
176176
if self.type and other.type and self.type != other.type:
177-
raise RuntimeError("Trying to merge incompatible node types.")
177+
raise RuntimeError(
178+
"Trying to merge incompatible node types. "
179+
+ f"Current node is {self.type}. Other is {other.type}"
180+
)
178181
self.type = self.type or other.type
179182
self.attributions.extend(other.attributions)
180183
for key, child in other.children.items():

0 commit comments

Comments
 (0)