aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Janovsky2022-05-12 17:34:55 +0200
committerAdam Janovsky2022-05-12 17:34:55 +0200
commit3e7fe67008f9344b7f663e08eda9962bc6f3d3aa (patch)
tree5fc25623c4831ab9dec53574013eb79c88fe67ce
parent34379d15eb6a3285fc5d92b67ca304bd1690e976 (diff)
downloadsec-certs-3e7fe67008f9344b7f663e08eda9962bc6f3d3aa.tar.gz
sec-certs-3e7fe67008f9344b7f663e08eda9962bc6f3d3aa.tar.zst
sec-certs-3e7fe67008f9344b7f663e08eda9962bc6f3d3aa.zip
fix empty raise, more detailed info about badly parsed html
-rw-r--r--sec_certs/dataset/common_criteria.py18
-rw-r--r--sec_certs/sample/common_criteria.py3
2 files changed, 13 insertions, 8 deletions
diff --git a/sec_certs/dataset/common_criteria.py b/sec_certs/dataset/common_criteria.py
index e9af7b7a..19f0dcd2 100644
--- a/sec_certs/dataset/common_criteria.py
+++ b/sec_certs/dataset/common_criteria.py
@@ -459,10 +459,11 @@ class CCDataset(Dataset[CommonCriteriaCert], ComplexSerializableType):
soup: BeautifulSoup, cert_status: str, table_id: str, category_string: str
) -> Dict[str, "CommonCriteriaCert"]:
tables = soup.find_all("table", id=table_id)
- assert len(tables) <= 1
- if not tables:
- return {}
+ if not len(tables) == 1:
+ raise ValueError(
+ f'The "{file.name}" was expected to contain exactly 1 <table> element. Instead, it contains: {len(tables)} <table> elements.'
+ )
table = tables[0]
rows = list(table.find_all("tr"))
@@ -475,9 +476,14 @@ class CCDataset(Dataset[CommonCriteriaCert], ComplexSerializableType):
# The following unused snippet extracts expected number of certs from the table
# caption_str = str(table.findAll('caption'))
# n_expected_certs = int(caption_str.split(category_string + ' – ')[1].split(' Certified Products')[0])
- table_certs = {
- x.dgst: x for x in [CommonCriteriaCert.from_html_row(row, cert_status, category_string) for row in body]
- }
+
+ try:
+ table_certs = {
+ x.dgst: x
+ for x in [CommonCriteriaCert.from_html_row(row, cert_status, category_string) for row in body]
+ }
+ except ValueError as e:
+ raise ValueError(f"Bad html file: {file.name} ({str(e)})") from e
return table_certs
diff --git a/sec_certs/sample/common_criteria.py b/sec_certs/sample/common_criteria.py
index 29789d2a..098054ac 100644
--- a/sec_certs/sample/common_criteria.py
+++ b/sec_certs/sample/common_criteria.py
@@ -540,8 +540,7 @@ class CommonCriteriaCert(
cells = list(row.find_all("td"))
if len(cells) != 7:
- logger.error("Unexpected number of cells in CC html row.")
- raise
+ raise ValueError(f"Unexpected number of <td> elements in CC html row. Expected: 7, actual: {len(cells)}")
name = CommonCriteriaCert._html_row_get_name(cells[0])
manufacturer = CommonCriteriaCert._html_row_get_manufacturer(cells[1])