Skip to content

Commit c38c822

Browse files
authored
better error message for schema cache miss (#7451)
1 parent c67530f commit c38c822

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

backend/infrahub/core/schema/schema_branch.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,23 @@ def get(self, name: str, duplicate: bool = True) -> MainSchemaTypes:
328328
elif name in self.templates:
329329
key = self.templates[name]
330330

331-
if key and duplicate:
332-
return self._cache[key].duplicate()
333-
if key and not duplicate:
334-
return self._cache[key]
331+
if not key:
332+
raise SchemaNotFoundError(
333+
branch_name=self.name, identifier=name, message=f"Unable to find the schema {name!r} in the registry"
334+
)
335335

336-
raise SchemaNotFoundError(
337-
branch_name=self.name, identifier=name, message=f"Unable to find the schema {name!r} in the registry"
338-
)
336+
schema: MainSchemaTypes | None = None
337+
try:
338+
schema = self._cache[key]
339+
except KeyError:
340+
pass
341+
342+
if not schema:
343+
raise ValueError(f"Schema {name!r} on branch {self.name} has incorrect hash: {key!r}")
344+
345+
if duplicate:
346+
return schema.duplicate()
347+
return schema
339348

340349
def get_node(self, name: str, duplicate: bool = True) -> NodeSchema:
341350
"""Access a specific NodeSchema, defined by its kind."""

0 commit comments

Comments
 (0)