Skip to content

Commit

Permalink
main: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
balinthaller committed Jan 29, 2021
1 parent e5868f5 commit bd71c33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
11 changes: 7 additions & 4 deletions flyover/loader/carte_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
21 changes: 12 additions & 9 deletions flyover/model/carte_table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit bd71c33

Please sign in to comment.