diff --git a/flyover/loader/carte_loader.py b/flyover/loader/carte_loader.py index da852a6..a3ae6ca 100644 --- a/flyover/loader/carte_loader.py +++ b/flyover/loader/carte_loader.py @@ -55,10 +55,13 @@ def load_table(self, record: Union[DatabuilderTableMetadata, TableMetadata]): if os.path.isfile(full_file_name): metadata, content = frontmatter.parse(full_file_name) - frontmatter_metadata = TableMetadata.from_frontmatter(metadata, content) - extractor_metadata = extractor_metadata.merge_with_existing( - frontmatter_metadata - ) + try: + frontmatter_metadata = TableMetadata.from_frontmatter(metadata, content) + extractor_metadata = extractor_metadata.merge_with_existing( + frontmatter_metadata + ) + except ValueError as e: + raise ValueError(f"{e}\nFile name: {full_file_name}") frontmatter.dump(full_file_name, *extractor_metadata.to_frontmatter()) diff --git a/flyover/model/carte_table_model.py b/flyover/model/carte_table_model.py index a461fdb..a34639d 100644 --- a/flyover/model/carte_table_model.py +++ b/flyover/model/carte_table_model.py @@ -112,15 +112,18 @@ def from_frontmatter(cls, metadata, content): for col_dict in metadata.get("columns", []) ] - return cls( - name=metadata["title"], - database=metadata.get("database", None), - description=content, - location=metadata.get("location", None), - connection=metadata.get("connection", None), - columns=columns, - table_type=TableType(metadata.get("table_type", "table")), - ) + try: + return cls( + name=metadata["title"], + database=metadata.get("database", None), + description=content, + location=metadata.get("location", None), + connection=metadata.get("connection", None), + columns=columns, + table_type=TableType(metadata.get("table_type", "table")), + ) + except KeyError as e: + raise ValueError(f"Key not found in frontmatter: {e}. Metadata: {metadata}") def to_frontmatter(self): metadata = {