Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
Don't swallow exceptions & better exception msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
dalito committed Jun 29, 2023
1 parent 89fc4ce commit a85b7b9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 47 deletions.
80 changes: 35 additions & 45 deletions vocexcel/convert_043.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import logging
from typing import List, Tuple

from openpyxl.worksheet.worksheet import Worksheet
from pydantic import ValidationError

try:
import models
from utils import ConversionError, load_workbook, split_and_tidy
from utils import ConversionError, split_and_tidy
except:
import sys

sys.path.append("..")
from vocexcel import models
from vocexcel.utils import ConversionError, load_workbook, split_and_tidy
from vocexcel.utils import ConversionError, split_and_tidy


# Checking how many colon's in string
Expand Down Expand Up @@ -65,17 +64,15 @@ def using_prefix_and_namespace_non_list_output(cell_value, prefix, s: Worksheet,
if split_c_prefix in prefix:
c = prefix[split_c_prefix] + split_c_added_component
else:
print(
f"the prefix used: '{split_c_prefix}' in sheet {s} and row {row} "
f"isn't included in the prefix sheet"
raise ConversionError(
f"The prefix '{split_c_prefix}' used in sheet {s} and row {row} "
f"isn't included in the prefix sheet."
)
raise Exception
else:
print(
raise ConversionError(
f"Something doesn't look right on row {row} and sheet {s}. "
f"Likely this isn't in http form or more colons are used than normal"
f"The problematic cell value is '{c}'. Correct URL form used?"
)
raise Exception
return c


Expand All @@ -92,50 +89,43 @@ def using_prefix_and_namespace_cs(cell_value, prefix):
if split_c_prefix in prefix:
c = prefix[split_c_prefix] + split_c_added_component
else:
print(
f"the prefix used: '{split_c_prefix}' in the concept scheme page"
f"isn't included in the prefix sheet"
raise ConversionError(
f"The prefix '{split_c_prefix}' used in the concept scheme page"
"isn't included in the prefix sheet."
)
raise Exception
else:
print(
f"Something doesn't look right in the concept scheme page. "
f"Likely the cells using prefixes aren't in http form or more colons are used than normal"
raise ConversionError(
"Something doesn't look right in the concept scheme page. "
f"The problematic cell value is '{c}'. Correct URL form used?"
)
raise Exception
return c


# prefix and namespace list with list output
def using_prefix_and_namespace(cell_value, prefix, s: Worksheet, row):
variables = []
for i in cell_value:
if cell_value is not None:
try:
c = i
if c.startswith("http://") or c.startswith("https://"):
pass
elif only_one_colon_in_str(c):
split_c_prefix = c.split(":")[0]
split_c_added_component = c.split(":")[1]

if split_c_prefix in prefix:
c = prefix[split_c_prefix] + split_c_added_component
else:
print(
f"the prefix used: '{split_c_prefix}' in sheet {s} and row {row} "
f"isn't included in the prefix sheet"
)
raise Exception
else:
print(
f"Something doesn't look right on row {row} and sheet {s}. "
f"Likely this isn't in http form or more colons are used than normal"
)
raise Exception
variables.append(c)
except Exception as e:
logging.exception(e)
for c in cell_value:
if not c:
continue
if c.startswith("http://") or c.startswith("https://"):
pass
elif only_one_colon_in_str(c):
split_c_prefix = c.split(":")[0]
split_c_added_component = c.split(":")[1]

if split_c_prefix in prefix:
c = prefix[split_c_prefix] + split_c_added_component
else:
raise ConversionError(
f"The prefix '{split_c_prefix}' used in sheet {s} and row {row} "
"isn't included in the prefix sheet."
)
else:
raise ConversionError(
f"Something doesn't look right on row {row} and sheet {s}. "
f"The problematic cell value is '{c}'. Correct URL form used?"
)
variables.append(c)
return variables


Expand Down
4 changes: 2 additions & 2 deletions vocexcel/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Tuple
from typing import List, Tuple

from openpyxl import load_workbook as _load_workbook
from openpyxl.workbook.workbook import Workbook
Expand Down Expand Up @@ -90,7 +90,7 @@ def string_is_http_iri(s: str) -> Tuple[bool, str]:
return True, ""


def all_strings_in_list_are_iris(l_: []) -> Tuple[bool, str]:
def all_strings_in_list_are_iris(l_: List) -> Tuple[bool, str]:
messages = []
if l_ is not None:
for item in l_:
Expand Down

0 comments on commit a85b7b9

Please sign in to comment.